aboutsummaryrefslogtreecommitdiffstats
path: root/tests/misc_dangerous_protocol.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-24 17:57:10 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-24 17:57:10 +0200
commita3dd207e3b1ebcbcb6cec0f703a695e51ae4ece0 (patch)
tree7b4bf040da23a03f38efe92a252e187a630a14f6 /tests/misc_dangerous_protocol.rs
parente7b3761c8cd6f0f902dd9927e4fbf2589465ed57 (diff)
downloadmarkdown-rs-a3dd207e3b1ebcbcb6cec0f703a695e51ae4ece0.tar.gz
markdown-rs-a3dd207e3b1ebcbcb6cec0f703a695e51ae4ece0.tar.bz2
markdown-rs-a3dd207e3b1ebcbcb6cec0f703a695e51ae4ece0.zip
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
Diffstat (limited to 'tests/misc_dangerous_protocol.rs')
-rw-r--r--tests/misc_dangerous_protocol.rs324
1 files changed, 161 insertions, 163 deletions
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))"),
-// "<p><img src=\"\" alt=\"\" /></p>",
-// "should be safe by default"
-// );
-
-// assert_eq!(
-// micromark("![](http://a)"),
-// "<p><img src=\"http://a\" alt=\"\" /></p>",
-// "should allow `http:`"
-// );
-
-// assert_eq!(
-// micromark("![](https://a)"),
-// "<p><img src=\"https://a\" alt=\"\" /></p>",
-// "should allow `https:`"
-// );
-
-// assert_eq!(
-// micromark("![](irc:///help)"),
-// "<p><img src=\"\" alt=\"\" /></p>",
-// "should not allow `irc:`"
-// );
-
-// assert_eq!(
-// micromark("![](mailto:a)"),
-// "<p><img src=\"\" alt=\"\" /></p>",
-// "should not allow `mailto:`"
-// );
-
-// assert_eq!(
-// micromark("![](#a)"),
-// "<p><img src=\"#a\" alt=\"\" /></p>",
-// "should allow a hash"
-// );
-
-// assert_eq!(
-// micromark("![](?a)"),
-// "<p><img src=\"?a\" alt=\"\" /></p>",
-// "should allow a search"
-// );
-
-// assert_eq!(
-// micromark("![](/a)"),
-// "<p><img src=\"/a\" alt=\"\" /></p>",
-// "should allow an absolute"
-// );
-
-// assert_eq!(
-// micromark("![](./a)"),
-// "<p><img src=\"./a\" alt=\"\" /></p>",
-// "should allow an relative"
-// );
-
-// assert_eq!(
-// micromark("![](../a)"),
-// "<p><img src=\"../a\" alt=\"\" /></p>",
-// "should allow an upwards relative"
-// );
-
-// assert_eq!(
-// micromark("![](a#b:c)"),
-// "<p><img src=\"a#b:c\" alt=\"\" /></p>",
-// "should allow a colon in a hash"
-// );
-
-// assert_eq!(
-// micromark("![](a?b:c)"),
-// "<p><img src=\"a?b:c\" alt=\"\" /></p>",
-// "should allow a colon in a search"
-// );
-
-// assert_eq!(
-// micromark("![](a/b:c)"),
-// "<p><img src=\"a/b:c\" alt=\"\" /></p>",
-// "should allow a colon in a path"
-// );
-// }
-
-// To do: link.
-// #[test]
-// fn dangerous_protocol_link() {
-// assert_eq!(
-// micromark("[](javascript:alert(1))"),
-// "<p><a href=\"\"></a></p>",
-// "should be safe by default"
-// );
-
-// assert_eq!(
-// micromark("[](http://a)"),
-// "<p><a href=\"http://a\"></a></p>",
-// "should allow `http:`"
-// );
-
-// assert_eq!(
-// micromark("[](https://a)"),
-// "<p><a href=\"https://a\"></a></p>",
-// "should allow `https:`"
-// );
-
-// assert_eq!(
-// micromark("[](irc:///help)"),
-// "<p><a href=\"irc:///help\"></a></p>",
-// "should allow `irc:`"
-// );
-
-// assert_eq!(
-// micromark("[](mailto:a)"),
-// "<p><a href=\"mailto:a\"></a></p>",
-// "should allow `mailto:`"
-// );
-
-// assert_eq!(
-// micromark("[](#a)"),
-// "<p><a href=\"#a\"></a></p>",
-// "should allow a hash"
-// );
-
-// assert_eq!(
-// micromark("[](?a)"),
-// "<p><a href=\"?a\"></a></p>",
-// "should allow a search"
-// );
-
-// assert_eq!(
-// micromark("[](/a)"),
-// "<p><a href=\"/a\"></a></p>",
-// "should allow an absolute"
-// );
-
-// assert_eq!(
-// micromark("[](./a)"),
-// "<p><a href=\"./a\"></a></p>",
-// "should allow an relative"
-// );
-
-// assert_eq!(
-// micromark("[](../a)"),
-// "<p><a href=\"../a\"></a></p>",
-// "should allow an upwards relative"
-// );
-
-// assert_eq!(
-// micromark("[](a#b:c)"),
-// "<p><a href=\"a#b:c\"></a></p>",
-// "should allow a colon in a hash"
-// );
-
-// assert_eq!(
-// micromark("[](a?b:c)"),
-// "<p><a href=\"a?b:c\"></a></p>",
-// "should allow a colon in a search"
-// );
-
-// assert_eq!(
-// micromark("[](a/b:c)"),
-// "<p><a href=\"a/b:c\"></a></p>",
-// "should allow a colon in a path"
-// );
-// }
+#[test]
+fn dangerous_protocol_image() {
+ assert_eq!(
+ micromark("![](javascript:alert(1))"),
+ "<p><img src=\"\" alt=\"\" /></p>",
+ "should be safe by default"
+ );
+
+ assert_eq!(
+ micromark("![](http://a)"),
+ "<p><img src=\"http://a\" alt=\"\" /></p>",
+ "should allow `http:`"
+ );
+
+ assert_eq!(
+ micromark("![](https://a)"),
+ "<p><img src=\"https://a\" alt=\"\" /></p>",
+ "should allow `https:`"
+ );
+
+ assert_eq!(
+ micromark("![](irc:///help)"),
+ "<p><img src=\"\" alt=\"\" /></p>",
+ "should not allow `irc:`"
+ );
+
+ assert_eq!(
+ micromark("![](mailto:a)"),
+ "<p><img src=\"\" alt=\"\" /></p>",
+ "should not allow `mailto:`"
+ );
+
+ assert_eq!(
+ micromark("![](#a)"),
+ "<p><img src=\"#a\" alt=\"\" /></p>",
+ "should allow a hash"
+ );
+
+ assert_eq!(
+ micromark("![](?a)"),
+ "<p><img src=\"?a\" alt=\"\" /></p>",
+ "should allow a search"
+ );
+
+ assert_eq!(
+ micromark("![](/a)"),
+ "<p><img src=\"/a\" alt=\"\" /></p>",
+ "should allow an absolute"
+ );
+
+ assert_eq!(
+ micromark("![](./a)"),
+ "<p><img src=\"./a\" alt=\"\" /></p>",
+ "should allow an relative"
+ );
+
+ assert_eq!(
+ micromark("![](../a)"),
+ "<p><img src=\"../a\" alt=\"\" /></p>",
+ "should allow an upwards relative"
+ );
+
+ assert_eq!(
+ micromark("![](a#b:c)"),
+ "<p><img src=\"a#b:c\" alt=\"\" /></p>",
+ "should allow a colon in a hash"
+ );
+
+ assert_eq!(
+ micromark("![](a?b:c)"),
+ "<p><img src=\"a?b:c\" alt=\"\" /></p>",
+ "should allow a colon in a search"
+ );
+
+ assert_eq!(
+ micromark("![](a/b:c)"),
+ "<p><img src=\"a/b:c\" alt=\"\" /></p>",
+ "should allow a colon in a path"
+ );
+}
+
+#[test]
+fn dangerous_protocol_link() {
+ assert_eq!(
+ micromark("[](javascript:alert(1))"),
+ "<p><a href=\"\"></a></p>",
+ "should be safe by default"
+ );
+
+ assert_eq!(
+ micromark("[](http://a)"),
+ "<p><a href=\"http://a\"></a></p>",
+ "should allow `http:`"
+ );
+
+ assert_eq!(
+ micromark("[](https://a)"),
+ "<p><a href=\"https://a\"></a></p>",
+ "should allow `https:`"
+ );
+
+ assert_eq!(
+ micromark("[](irc:///help)"),
+ "<p><a href=\"irc:///help\"></a></p>",
+ "should allow `irc:`"
+ );
+
+ assert_eq!(
+ micromark("[](mailto:a)"),
+ "<p><a href=\"mailto:a\"></a></p>",
+ "should allow `mailto:`"
+ );
+
+ assert_eq!(
+ micromark("[](#a)"),
+ "<p><a href=\"#a\"></a></p>",
+ "should allow a hash"
+ );
+
+ assert_eq!(
+ micromark("[](?a)"),
+ "<p><a href=\"?a\"></a></p>",
+ "should allow a search"
+ );
+
+ assert_eq!(
+ micromark("[](/a)"),
+ "<p><a href=\"/a\"></a></p>",
+ "should allow an absolute"
+ );
+
+ assert_eq!(
+ micromark("[](./a)"),
+ "<p><a href=\"./a\"></a></p>",
+ "should allow an relative"
+ );
+
+ assert_eq!(
+ micromark("[](../a)"),
+ "<p><a href=\"../a\"></a></p>",
+ "should allow an upwards relative"
+ );
+
+ assert_eq!(
+ micromark("[](a#b:c)"),
+ "<p><a href=\"a#b:c\"></a></p>",
+ "should allow a colon in a hash"
+ );
+
+ assert_eq!(
+ micromark("[](a?b:c)"),
+ "<p><a href=\"a?b:c\"></a></p>",
+ "should allow a colon in a search"
+ );
+
+ assert_eq!(
+ micromark("[](a/b:c)"),
+ "<p><a href=\"a/b:c\"></a></p>",
+ "should allow a colon in a path"
+ );
+}