markdown-rs icon indicating copy to clipboard operation
markdown-rs copied to clipboard

mdast_util_to_markdown panics while trying to format UTF text with trailing spaces

Open johnlepikhin opened this issue 10 months ago • 4 comments

Hi there,

There is a bug somewhere in state.rs → container_phrasing(), which makes it panic with the message like "byte index 212 is not a char boundary" at line 245. I reproduced it in simple test: https://github.com/johnlepikhin/markdown-rs/commit/e4c451ad85a1a3348ea094bfa6dd10d0a4e12178. Please note that source markdown at lines 7-9 contains sequence:

<UTF-8 character> <SPACE> <SPACE> <NEWLINE>

johnlepikhin avatar Mar 05 '25 20:03 johnlepikhin

Found another case which reproduces probably the same issue: https://github.com/johnlepikhin/markdown-rs/commit/3614cbefddb6e366724a02fcc7b1f9f2c60ce048. The first character in markdown document is UTF-8.

johnlepikhin avatar Mar 05 '25 20:03 johnlepikhin

The former might be variation on https://github.com/wooorm/markdown-rs/pull/31 The latter looks like a variant of https://github.com/wooorm/markdown-rs/pull/22

ChristianMurphy avatar Mar 05 '25 21:03 ChristianMurphy

I was able to reproduce the issue using the second test case you provided and I fixed it in here #170

Can you check if you can reproduce the panic that's happening in the first test case using the fix provided in the PR ?

bnchi avatar Mar 09 '25 12:03 bnchi

Thank you, @bnchi! Both cases were fixed.

johnlepikhin avatar Mar 10 '25 10:03 johnlepikhin