markdown-it-rust / markdown-it

markdown-it js library rewritten in rust
Other
79 stars 9 forks source link

panic on "**...**" smartquotes #26

Closed phiresky closed 1 year ago

phiresky commented 1 year ago

this is causing lemmy to break. reference: https://github.com/LemmyNet/lemmy/issues/3411 :

panicked at 'called `Option::unwrap()` on a `None` value', /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/markdown-it-0.5.0/src/plugins/extra/smartquotes.rs:518:51

code:

static MARKDOWN_PARSER: Lazy<MarkdownIt> = Lazy::new(|| {
  let mut parser = MarkdownIt::new();
  markdown_it::plugins::cmark::add(&mut parser);
  markdown_it::plugins::extra::add(&mut parser);
  spoiler_rule::add(&mut parser);

  parser
});

pub fn markdown_to_html(text: &str) -> String {
  MARKDOWN_PARSER.parse(text).xrender()
}
rlidwka commented 1 year ago

please try master branch, it might be related to https://github.com/rlidwka/markdown-it.rs/commit/1773eee36016dd947eaabc919c12cbabb79568fd, which was fixed recently

also, can you provide full text, on which parser breaks?

phiresky commented 1 year ago

just "**...**" breaks it

rlidwka commented 1 year ago

confirmed, still a bug, will fix today or tomorrow

here's minimal sample:

fn main() {
    let mut parser = markdown_it::MarkdownIt::new();
    markdown_it::plugins::cmark::add(&mut parser);
    markdown_it::plugins::extra::add(&mut parser);
    println!("{}", parser.parse("\"**...**\"").render());
}

@black-puppydog, any ideas?

rlidwka commented 1 year ago

turned out to be incorrect non-ascii handling

fixed and published as 0.5.1, thanks for reporting