From 4277dac07db06f24ba30a75b4c1dec542e32dae8 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 13 Jun 2022 14:50:48 +0200 Subject: Add support for sanitizing urls * Add support for properly encoding characters in urls * Add support for sanitizing potentially dangerous urls * Add safe defaults, optionally live dangerously --- tests/autolink.rs | 63 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 25 deletions(-) (limited to 'tests/autolink.rs') diff --git a/tests/autolink.rs b/tests/autolink.rs index fc49dcb..9d394d7 100644 --- a/tests/autolink.rs +++ b/tests/autolink.rs @@ -1,5 +1,10 @@ extern crate micromark; -use micromark::micromark; +use micromark::{micromark, micromark_with_options, CompileOptions}; + +const DANGER: &CompileOptions = &CompileOptions { + allow_dangerous_html: true, + allow_dangerous_protocol: true, +}; #[test] fn autolink() { @@ -33,19 +38,29 @@ fn autolink() { "should support protocol autolinks in uppercase" ); - // To do: safety. - // assert_eq!( - // micromark("", {allowDangerousProtocol: true}), - // "

a+b+c:d

", - // "should support protocol autolinks w/ incorrect URIs (1)" - // ); + assert_eq!( + micromark(""), + "

a+b+c:d

", + "should support protocol autolinks w/ incorrect URIs (1, default)" + ); - // To do: safety. - // assert_eq!( - // micromark("", {allowDangerousProtocol: true}), - // "

made-up-scheme://foo,bar

", - // "should support protocol autolinks w/ incorrect URIs (2)" - // ); + assert_eq!( + micromark_with_options("", DANGER), + "

a+b+c:d

", + "should support protocol autolinks w/ incorrect URIs (1, danger)" + ); + + assert_eq!( + micromark(""), + "

made-up-scheme://foo,bar

", + "should support protocol autolinks w/ incorrect URIs (2, default)" + ); + + assert_eq!( + micromark_with_options("", DANGER), + "

made-up-scheme://foo,bar

", + "should support protocol autolinks w/ incorrect URIs (2, danger)" + ); assert_eq!( micromark(""), @@ -53,12 +68,11 @@ fn autolink() { "should support protocol autolinks w/ incorrect URIs (3)" ); - // To do: safety. - // assert_eq!( - // micromark("", {allowDangerousProtocol: true}), - // "

localhost:5001/foo

", - // "should support protocol autolinks w/ incorrect URIs (4)" - // ); + assert_eq!( + micromark_with_options("", DANGER), + "

localhost:5001/foo

", + "should support protocol autolinks w/ incorrect URIs (4)" + ); assert_eq!( micromark(""), @@ -66,12 +80,11 @@ fn autolink() { "should not support protocol autolinks w/ spaces" ); - // To do: encode urls. - // assert_eq!( - // micromark(""), - // "

http://example.com/\\[\\

", - // "should not support character escapes in protocol autolinks" - // ); + assert_eq!( + micromark(""), + "

http://example.com/\\[\\

", + "should not support character escapes in protocol autolinks" + ); assert_eq!( micromark(""), -- cgit