From a3dd207e3b1ebcbcb6cec0f703a695e51ae4ece0 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 24 Jun 2022 17:57:10 +0200 Subject: Add link, images (resource) This is still some messy code that needs cleaning up, but it adds support for links and images, of the resource kind (`[a](b)`). References (`[a][b]`) are parsed and will soon be supported, but need matching. * Fix bug to pad percent-encoded bytes when normalizing urls * Fix bug with escapes counting as balancing in destination * Add `space_or_tab_one_line_ending`, to parse whitespace including up to one line ending (but not a blank line) * Add `ParserState` to share codes, definitions, etc --- tests/misc_dangerous_protocol.rs | 324 +++++++++++++++++++-------------------- 1 file changed, 161 insertions(+), 163 deletions(-) (limited to 'tests/misc_dangerous_protocol.rs') diff --git a/tests/misc_dangerous_protocol.rs b/tests/misc_dangerous_protocol.rs index 6f759e3..3aa042a 100644 --- a/tests/misc_dangerous_protocol.rs +++ b/tests/misc_dangerous_protocol.rs @@ -34,166 +34,164 @@ fn dangerous_protocol_autolink() { ); } -// To do: image. -// #[test] -// fn dangerous_protocol_image() { -// assert_eq!( -// micromark("![](javascript:alert(1))"), -// "

\"\"

", -// "should be safe by default" -// ); - -// assert_eq!( -// micromark("![](http://a)"), -// "

\"\"

", -// "should allow `http:`" -// ); - -// assert_eq!( -// micromark("![](https://a)"), -// "

\"\"

", -// "should allow `https:`" -// ); - -// assert_eq!( -// micromark("![](irc:///help)"), -// "

\"\"

", -// "should not allow `irc:`" -// ); - -// assert_eq!( -// micromark("![](mailto:a)"), -// "

\"\"

", -// "should not allow `mailto:`" -// ); - -// assert_eq!( -// micromark("![](#a)"), -// "

\"\"

", -// "should allow a hash" -// ); - -// assert_eq!( -// micromark("![](?a)"), -// "

\"\"

", -// "should allow a search" -// ); - -// assert_eq!( -// micromark("![](/a)"), -// "

\"\"

", -// "should allow an absolute" -// ); - -// assert_eq!( -// micromark("![](./a)"), -// "

\"\"

", -// "should allow an relative" -// ); - -// assert_eq!( -// micromark("![](../a)"), -// "

\"\"

", -// "should allow an upwards relative" -// ); - -// assert_eq!( -// micromark("![](a#b:c)"), -// "

\"\"

", -// "should allow a colon in a hash" -// ); - -// assert_eq!( -// micromark("![](a?b:c)"), -// "

\"\"

", -// "should allow a colon in a search" -// ); - -// assert_eq!( -// micromark("![](a/b:c)"), -// "

\"\"

", -// "should allow a colon in a path" -// ); -// } - -// To do: link. -// #[test] -// fn dangerous_protocol_link() { -// assert_eq!( -// micromark("[](javascript:alert(1))"), -// "

", -// "should be safe by default" -// ); - -// assert_eq!( -// micromark("[](http://a)"), -// "

", -// "should allow `http:`" -// ); - -// assert_eq!( -// micromark("[](https://a)"), -// "

", -// "should allow `https:`" -// ); - -// assert_eq!( -// micromark("[](irc:///help)"), -// "

", -// "should allow `irc:`" -// ); - -// assert_eq!( -// micromark("[](mailto:a)"), -// "

", -// "should allow `mailto:`" -// ); - -// assert_eq!( -// micromark("[](#a)"), -// "

", -// "should allow a hash" -// ); - -// assert_eq!( -// micromark("[](?a)"), -// "

", -// "should allow a search" -// ); - -// assert_eq!( -// micromark("[](/a)"), -// "

", -// "should allow an absolute" -// ); - -// assert_eq!( -// micromark("[](./a)"), -// "

", -// "should allow an relative" -// ); - -// assert_eq!( -// micromark("[](../a)"), -// "

", -// "should allow an upwards relative" -// ); - -// assert_eq!( -// micromark("[](a#b:c)"), -// "

", -// "should allow a colon in a hash" -// ); - -// assert_eq!( -// micromark("[](a?b:c)"), -// "

", -// "should allow a colon in a search" -// ); - -// assert_eq!( -// micromark("[](a/b:c)"), -// "

", -// "should allow a colon in a path" -// ); -// } +#[test] +fn dangerous_protocol_image() { + assert_eq!( + micromark("![](javascript:alert(1))"), + "

\"\"

", + "should be safe by default" + ); + + assert_eq!( + micromark("![](http://a)"), + "

\"\"

", + "should allow `http:`" + ); + + assert_eq!( + micromark("![](https://a)"), + "

\"\"

", + "should allow `https:`" + ); + + assert_eq!( + micromark("![](irc:///help)"), + "

\"\"

", + "should not allow `irc:`" + ); + + assert_eq!( + micromark("![](mailto:a)"), + "

\"\"

", + "should not allow `mailto:`" + ); + + assert_eq!( + micromark("![](#a)"), + "

\"\"

", + "should allow a hash" + ); + + assert_eq!( + micromark("![](?a)"), + "

\"\"

", + "should allow a search" + ); + + assert_eq!( + micromark("![](/a)"), + "

\"\"

", + "should allow an absolute" + ); + + assert_eq!( + micromark("![](./a)"), + "

\"\"

", + "should allow an relative" + ); + + assert_eq!( + micromark("![](../a)"), + "

\"\"

", + "should allow an upwards relative" + ); + + assert_eq!( + micromark("![](a#b:c)"), + "

\"\"

", + "should allow a colon in a hash" + ); + + assert_eq!( + micromark("![](a?b:c)"), + "

\"\"

", + "should allow a colon in a search" + ); + + assert_eq!( + micromark("![](a/b:c)"), + "

\"\"

", + "should allow a colon in a path" + ); +} + +#[test] +fn dangerous_protocol_link() { + assert_eq!( + micromark("[](javascript:alert(1))"), + "

", + "should be safe by default" + ); + + assert_eq!( + micromark("[](http://a)"), + "

", + "should allow `http:`" + ); + + assert_eq!( + micromark("[](https://a)"), + "

", + "should allow `https:`" + ); + + assert_eq!( + micromark("[](irc:///help)"), + "

", + "should allow `irc:`" + ); + + assert_eq!( + micromark("[](mailto:a)"), + "

", + "should allow `mailto:`" + ); + + assert_eq!( + micromark("[](#a)"), + "

", + "should allow a hash" + ); + + assert_eq!( + micromark("[](?a)"), + "

", + "should allow a search" + ); + + assert_eq!( + micromark("[](/a)"), + "

", + "should allow an absolute" + ); + + assert_eq!( + micromark("[](./a)"), + "

", + "should allow an relative" + ); + + assert_eq!( + micromark("[](../a)"), + "

", + "should allow an upwards relative" + ); + + assert_eq!( + micromark("[](a#b:c)"), + "

", + "should allow a colon in a hash" + ); + + assert_eq!( + micromark("[](a?b:c)"), + "

", + "should allow a colon in a search" + ); + + assert_eq!( + micromark("[](a/b:c)"), + "

", + "should allow a colon in a path" + ); +} -- cgit