From b2b772e5148083bd5d1407e42e7ee1bd2e4a7c4a Mon Sep 17 00:00:00 2001 From: Ashe Connor Date: Tue, 27 Nov 2018 10:35:30 +1100 Subject: [PATCH 1/5] WIP: latest upstream --- src/main.rs | 8 ++++---- vendor/cmark-gfm | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4774787c..8de438ce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,9 +47,9 @@ fn main() -> Result<(), Box> { .takes_value(true), ) .arg( - clap::Arg::with_name("safe") - .long("safe") - .help("Suppress raw HTML and dangerous URLs"), + clap::Arg::with_name("unsafe") + .long("unsafe") + .help("Allow raw HTML and dangerous URLs"), ) .arg( clap::Arg::with_name("extension") @@ -114,7 +114,7 @@ fn main() -> Result<(), Box> { default_info_string: matches .value_of("default-info-string") .map(|e| e.to_owned()), - safe: matches.is_present("safe"), + safe: !matches.is_present("unsafe"), ext_strikethrough: exts.remove("strikethrough"), ext_tagfilter: exts.remove("tagfilter"), ext_table: exts.remove("table"), diff --git a/vendor/cmark-gfm b/vendor/cmark-gfm index 1512c9cf..42f5a52d 160000 --- a/vendor/cmark-gfm +++ b/vendor/cmark-gfm @@ -1 +1 @@ -Subproject commit 1512c9cf5671583d21d0c0f7e936e830b770e803 +Subproject commit 42f5a52dc345fe2df4808caa36d10e1557e2a1ce From aa5cf38649db1f206c6e951b1502544e291e6de7 Mon Sep 17 00:00:00 2001 From: Ashe Connor Date: Tue, 27 Nov 2018 10:51:00 +1100 Subject: [PATCH 2/5] safe/unsafe inversion --- src/html.rs | 8 +++---- src/main.rs | 2 +- src/parser/mod.rs | 20 ++++++++-------- src/tests.rs | 59 +++++++++++++++++++++++++++++++---------------- 4 files changed, 55 insertions(+), 34 deletions(-) diff --git a/src/html.rs b/src/html.rs index 2af19f1e..4d19b740 100644 --- a/src/html.rs +++ b/src/html.rs @@ -450,7 +450,7 @@ impl<'o> HtmlFormatter<'o> { }, NodeValue::HtmlBlock(ref nhb) => if entering { self.cr()?; - if self.options.safe { + if !self.options.unsafe_ { self.output.write_all(b"")?; } else if self.options.ext_tagfilter { tagfilter_block(&nhb.literal, &mut self.output)?; @@ -509,7 +509,7 @@ impl<'o> HtmlFormatter<'o> { self.output.write_all(b"")?; }, NodeValue::HtmlInline(ref literal) => if entering { - if self.options.safe { + if !self.options.unsafe_ { self.output.write_all(b"")?; } else if self.options.ext_tagfilter && tagfilter(literal) { self.output.write_all(b"<")?; @@ -540,7 +540,7 @@ impl<'o> HtmlFormatter<'o> { }, NodeValue::Link(ref nl) => if entering { self.output.write_all(b" HtmlFormatter<'o> { }, NodeValue::Image(ref nl) => if entering { self.output.write_all(b"\"")?; Result<(), Box> { default_info_string: matches .value_of("default-info-string") .map(|e| e.to_owned()), - safe: !matches.is_present("unsafe"), + unsafe_: matches.is_present("unsafe"), ext_strikethrough: exts.remove("strikethrough"), ext_tagfilter: exts.remove("tagfilter"), ext_table: exts.remove("table"), diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 7ae7d80a..e4d34627 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -153,7 +153,7 @@ pub struct ComrakOptions { /// ``` pub default_info_string: Option, - /// Disable rendering of raw HTML and potentially dangerous links. + /// Allow rendering of raw HTML and potentially dangerous links. /// /// ``` /// # use comrak::{markdown_to_html, ComrakOptions}; @@ -164,19 +164,19 @@ pub struct ComrakOptions { /// [Safe](http://commonmark.org).\n"; /// /// assert_eq!(markdown_to_html(input, &options), - /// "\n\ - ///

Possibly annoying.

\n\ - ///

Dangerous.

\n\ - ///

Safe.

\n"); - /// - /// options.safe = true; - /// assert_eq!(markdown_to_html(input, &options), /// "\n\ ///

Possibly annoying.

\n\ ///

Dangerous.

\n\ ///

Safe.

\n"); + /// + /// options.unsafe_ = true; + /// assert_eq!(markdown_to_html(input, &options), + /// "\n\ + ///

Possibly annoying.

\n\ + ///

Dangerous.

\n\ + ///

Safe.

\n"); /// ``` - pub safe: bool, + pub unsafe_: bool, /// Enables the /// [strikethrough extension](https://github.github.com/gfm/#strikethrough-extension-) @@ -200,6 +200,7 @@ pub struct ComrakOptions { /// ``` /// # use comrak::{markdown_to_html, ComrakOptions}; /// let options = ComrakOptions { + /// unsafe_: true, /// ext_tagfilter: true, /// ..ComrakOptions::default() /// }; @@ -247,6 +248,7 @@ pub struct ComrakOptions { /// ``` /// # use comrak::{markdown_to_html, ComrakOptions}; /// let options = ComrakOptions { + /// unsafe_: true, /// ext_tasklist: true, /// ..ComrakOptions::default() /// }; diff --git a/src/tests.rs b/src/tests.rs index d7e1c16c..c9d8696a 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -51,6 +51,17 @@ where ); } +macro_rules! html_opts { + ([$($opt:ident),*], $lhs:expr, $rhs:expr,) => { + html_opts!([$($opt),*], $lhs, $rhs) + }; + ([$($opt:ident),*], $lhs:expr, $rhs:expr) => { + html_opts($lhs, $rhs, |opts| { + $(opts.$opt = true;)* + }); + }; +} + #[cfg(feature = "benchmarks")] #[cfg_attr(feature = "benchmarks", bench)] fn bench_progit(b: &mut Bencher) { @@ -141,7 +152,8 @@ fn setext_heading() { #[test] fn html_block_1() { - html( + html_opts!( + [unsafe_], concat!( " *ok*\n", @@ -179,7 +191,8 @@ fn html_block_1() { #[test] fn html_block_2() { - html( + html_opts!( + [unsafe_], concat!(" *hi*\n", "*hi*\n"), concat!( "