-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from hoodie/feature/escaping
fix escaping
- Loading branch information
Showing
7 changed files
with
187 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,12 +166,22 @@ fn test_property() { | |
); | ||
|
||
// TODO: newlines followed by spaces must be ignored | ||
assert_parser!( | ||
property, | ||
"KEY4;foo=bar:VALUE\\n newline separated\n", | ||
Property { | ||
name: "KEY4".into(), | ||
val: "VALUE\n newline separated".into(), | ||
params: vec![Parameter::new_ref("foo", Some("bar"))] | ||
} | ||
); | ||
|
||
assert_parser!( | ||
property, | ||
"KEY3;foo=bar:VALUE\\n newline separated\n", | ||
Property { | ||
name: "KEY3".into(), | ||
val: "VALUE\\n newline separated".into(), | ||
val: "VALUE\n newline separated".into(), | ||
params: vec![Parameter::new_ref("foo", Some("bar"))] | ||
} | ||
); | ||
|
@@ -192,7 +202,6 @@ fn test_property_with_dash() { | |
|
||
#[test] | ||
fn parse_properties_from_rfc() { | ||
// TODO: newlines followed by spaces must be ignored | ||
assert_parser!( | ||
property, | ||
"home.tel;type=fax,voice,msg:+49 3581 123456\n", | ||
|
@@ -202,7 +211,7 @@ fn parse_properties_from_rfc() { | |
params: vec![Parameter::new_ref("type", Some("fax,voice,msg"),)] | ||
} | ||
); | ||
// TODO: newlines followed by spaces must be ignored | ||
|
||
assert_parser!( | ||
property, | ||
"email;internet:[email protected]\n", | ||
|
@@ -221,7 +230,7 @@ fn parse_property_with_breaks() { | |
|
||
let expectation = Property { | ||
name: "DESCRIPTION".into(), | ||
val: "Hey, I'm gonna have a party\\n BYOB: Bring your own beer.\\n Hendrik\\n".into(), | ||
val: "Hey, I'm gonna have a party\n BYOB: Bring your own beer.\n Hendrik\n".into(), | ||
params: vec![], | ||
}; | ||
|
||
|
@@ -309,8 +318,9 @@ pub fn property<'a, E: ParseError<&'a str> + ContextError<&'a str>>( | |
// this is for single line prop parsing, just so I can leave off the '\n' | ||
take_while(|_| true), | ||
)) | ||
.map(ParseString::from), | ||
), // val TODO: replace this with something simpler! | ||
.map(ParseString::from) | ||
.map(ParseString::unescape_text), | ||
), | ||
), | ||
context( | ||
"no-value property", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#![cfg(feature = "parser")] | ||
use std::str::FromStr; | ||
|
||
use chrono::*; | ||
use icalendar::*; | ||
// use pretty_assertions::assert_eq; | ||
|
||
fn get_summary(calendar: &Calendar) -> &str { | ||
calendar.components[0] | ||
.as_event() | ||
.unwrap() | ||
.get_summary() | ||
.unwrap() | ||
} | ||
fn get_description(calendar: &Calendar) -> &str { | ||
calendar.components[0] | ||
.as_event() | ||
.unwrap() | ||
.get_description() | ||
.unwrap() | ||
} | ||
|
||
fn init_test_event() -> (&'static str, &'static str, Calendar) { | ||
let summary = ";IMPORTANCE=very;test event"; | ||
let description = "this, contains: many escapeworthy->\n<-;characters"; | ||
|
||
let event = Event::new() | ||
.summary(summary) | ||
.description(description) | ||
.starts(Utc::now()) | ||
.class(Class::Confidential) | ||
.ends(Utc::now() + Duration::days(1)) | ||
.append_property( | ||
Property::new("TEST", "FOOBAR") | ||
.add_parameter("IMPORTANCE", "very") | ||
.add_parameter("COMPLEX", r#"this is code; I think"#) | ||
.add_parameter("keyval", "color:red") | ||
.done(), | ||
) | ||
.uid("my.own.id") | ||
.done(); | ||
|
||
let todo = Todo::new().summary("Buy some: milk").done(); | ||
|
||
let mut built_calendar = Calendar::new(); | ||
built_calendar.push(event); | ||
built_calendar.push(todo); | ||
(summary, description, built_calendar) | ||
} | ||
|
||
#[test] | ||
#[ignore = "equality difficult"] | ||
fn serializes_correctly() { | ||
let (_, _, built_calendar) = init_test_event(); | ||
println!("built calendar:\n{:#?}", built_calendar); // inner representation of what we built | ||
|
||
let serialized = built_calendar.to_string(); | ||
println!("serialized: {}", &serialized); // print what we built | ||
|
||
let from_parsed = Calendar::from_str(&serialized).unwrap(); | ||
println!("parsed again:\n{:#?}", from_parsed); // inner representation of what we built and then parsed | ||
|
||
assert_eq!(built_calendar, from_parsed) | ||
} | ||
|
||
#[test] | ||
fn escape_late() { | ||
let (summary, description, built_calendar) = init_test_event(); | ||
println!("built calendar:\n{:#?}", built_calendar); // inner representation of what we built | ||
|
||
let serialized = built_calendar.to_string(); | ||
println!("serialized: {}", &serialized); // print what we built | ||
|
||
let from_parsed = Calendar::from_str(&serialized).unwrap(); | ||
println!("parsed again:\n{:#?}", from_parsed); // inner representation of what we built and then parsed | ||
|
||
// these should not be escaped | ||
assert_eq!(get_summary(&built_calendar), summary); | ||
assert_eq!(get_description(&built_calendar), description); | ||
} | ||
|
||
#[test] | ||
fn unescape_text() { | ||
let (summary, description, built_calendar) = init_test_event(); | ||
println!("built calendar:\n{:#?}", built_calendar); // inner representation of what we built | ||
|
||
let serialized = built_calendar.to_string(); | ||
println!("serialized:\n {}", &serialized); // print what we built | ||
|
||
let from_parsed = Calendar::from_str(&serialized).unwrap(); | ||
println!("parsed again:\n{:#?}", from_parsed); // inner representation of what we built and then parsed | ||
|
||
assert_eq!(get_summary(&from_parsed), summary); | ||
assert_eq!(get_description(&from_parsed), description); | ||
} | ||
|
||
#[test] | ||
fn reparse_equivalence() { | ||
let (_summary, _description, built_calendar) = init_test_event(); | ||
println!("built calendar:\n{:#?}", built_calendar); // inner representation of what we built | ||
|
||
let serialized = built_calendar.to_string(); | ||
println!("serialized: {}", &serialized); // print what we built | ||
|
||
let from_parsed = Calendar::from_str(&serialized).unwrap(); | ||
println!("parsed again:\n{:#?}", from_parsed); // inner representation of what we built and then parsed | ||
|
||
assert_eq!(get_summary(&built_calendar), get_summary(&from_parsed),); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ END:VTODO\r | |
BEGIN:VALARM\r | ||
TRIGGER;RELATED=END:-P2D\r | ||
ACTION:EMAIL\r | ||
ATTENDEE:mailto:[email protected]\r | ||
ATTENDEE:\"mailto:[email protected]\"\r | ||
SUMMARY:*** REMINDER: SEND AGENDA FOR WEEKLY STAFF MEETING ***\r | ||
DESCRIPTION:A draft agenda needs to be sent out to the attendees to the wee\r | ||
kly managers meeting (MGR-LIST). Attached is a pointer the document templat\r | ||
|