Skip to content

Commit

Permalink
Skip over some known divergence between implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Jan 23, 2024
1 parent d3974b5 commit 30bbeb4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
5 changes: 0 additions & 5 deletions fuzz/fuzz_targets/commonmark_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ fuzz_target!(|text: String| {
return;
}

// https://github.com/raphlinus/pulldown-cmark/issues/659
if text.contains("<") {
return;
}

// There are some trivial differences due to trailing whitespace.
let text = text
.lines()
Expand Down
21 changes: 20 additions & 1 deletion fuzz/fuzz_targets/pandoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ fuzz_target!(|text: String| {
if text.contains("[^\r") {
return;
}
if text.contains(" ]") {
return;
}
if text.contains("\t]") {
return;
}
if text.contains("\n]") {
return;
}
if text.contains("\r]") {
return;
}
if text.contains("[ ") {
return;
}
Expand All @@ -48,6 +60,12 @@ fuzz_target!(|text: String| {
if text.contains("[\r") {
return;
}
if text.contains("`") {
return;
}
if text.contains(">>>>>") {
return;
}

if text.bytes().any(|b| b > 127) {
return;
Expand Down Expand Up @@ -83,7 +101,8 @@ fuzz_target!(|text: String| {
footstack.pop();
}
Event::FootnoteReference(id) => {
if footstack.contains(&id.trim().to_string()) {
if !footstack.is_empty() {
//if footstack.contains(&id.trim().to_string()) {
return;
}
}
Expand Down
11 changes: 7 additions & 4 deletions fuzz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn pulldown_cmark(text: &str) -> Vec<Event<'_>> {
/// Send Markdown `text` to `pulldown-cmark` and return Markdown
/// events.
pub fn pulldown_cmark_ext(text: &str) -> Vec<Event<'_>> {
Parser::new_ext(text, pulldown_cmark::Options::ENABLE_TABLES).collect()
Parser::new_ext(text, pulldown_cmark::Options::ENABLE_FOOTNOTES).collect()
}

pub struct PandocHandle {
Expand Down Expand Up @@ -85,7 +85,7 @@ impl PandocHandle {
let PandocHandle { client, port, .. } = self;
let request_json = serde_json::to_string(&PandocRequest {
text,
from: "commonmark+pipe_tables",
from: "commonmark+footnotes",
to: "json",
})?;
let res = client.post(&format!("http://localhost:{port}"))
Expand Down Expand Up @@ -871,10 +871,13 @@ pub fn normalize(events: Vec<Event<'_>>) -> Vec<Event<'_>> {
dest_url,
title,
id: _,
link_type,
..
}) => vec![Event::Start(Tag::Link {
link_type: LinkType::Inline,
dest_url: dest_url.clone(),
// pandoc and commonmark.js both turn <i@e> into <mailto:i@e> and don't
// distinguish between them
dest_url: format!("{e}{dest_url}", e = if link_type == LinkType::Email { "mailto:" } else { "" }).into(),
title: title.clone(),
// commonmark.js does not record the id, either
id: "".into(),
Expand Down Expand Up @@ -903,7 +906,7 @@ pub fn normalize(events: Vec<Event<'_>>) -> Vec<Event<'_>> {
Event::Html(html) if html.is_empty() => vec![],

// pulldown-cmark includes trailing newlines in HTML.
Event::Html(html) => vec![Event::Html(html.trim_end_matches('\n').to_string().into())],
Event::Html(html) => vec![Event::Html(html.trim().to_string().into())],

event => vec![event],
})
Expand Down

0 comments on commit 30bbeb4

Please sign in to comment.