Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nondeterministic output with garbled strings #14

Closed
jgm opened this issue Mar 13, 2019 · 5 comments
Closed

Nondeterministic output with garbled strings #14

jgm opened this issue Mar 13, 2019 · 5 comments

Comments

@jgm
Copy link
Owner

jgm commented Mar 13, 2019

I suspect this is a memory handling bug related to PR #13; see the discussion there.

@andersk can you have a look? I'm almost positive it's an issue with your PR, rather than with cmark.

@kivikakk this affects cmark-gfm too.

If a quick fix is not forthcoming, we should roll back PR #13 and make a new release.

Prelude CMarkGFM> nodeToCommonmark [] Nothing $ Node Nothing DOCUMENT [Node Nothing PARAGRAPH [Node Nothing (TEXT "^") []]]
"^\n"
Prelude CMarkGFM> nodeToCommonmark [] Nothing $ Node Nothing DOCUMENT [Node Nothing PARAGRAPH [Node Nothing (TEXT "^") []]]
"^Z\n"
Prelude CMarkGFM> nodeToCommonmark [] Nothing $ Node Nothing DOCUMENT [Node Nothing PARAGRAPH [Node Nothing (TEXT "^") []]]
"^\\*%\n"

Also reproducible with other strings:

Prelude CMarkGFM> nodeToCommonmark [] Nothing $ Node Nothing DOCUMENT [Node Nothing PARAGRAPH [Node Nothing (TEXT " ") []]]
" p@R\n"
Prelude CMarkGFM> nodeToCommonmark [] Nothing $ Node Nothing DOCUMENT [Node Nothing PARAGRAPH [Node Nothing (TEXT " ") []]]
" \n"
Prelude CMarkGFM> nodeToCommonmark [] Nothing $ Node Nothing DOCUMENT [Node Nothing PARAGRAPH [Node Nothing (TEXT "hi") []]]
"hiC\SOHB\n"

Affects other writers as well:

Prelude CMarkGFM> nodeToMan [] Nothing $ Node Nothing DOCUMENT [Node Nothing PARAGRAPH [Node Nothing (TEXT "hi") []]]
".PP\nhiz\v\SOH\n"
Prelude CMarkGFM> nodeToLaTeX [] Nothing $ Node Nothing DOCUMENT [Node Nothing PARAGRAPH [Node Nothing (TEXT "hi") []]]
"hiaR\n"
Prelude CMarkGFM> nodeToXml []  $ Node Nothing DOCUMENT [Node Nothing PARAGRAPH [Node Nothing (TEXT "hi") []]]
"*** Exception: Cannot decode byte '\xd2': Data.Text.Internal.Encoding.decodeUtf8: Invalid UTF-8 stream
Prelude CMarkGFM> nodeToHtml [] [] $ Node Nothing DOCUMENT [Node Nothing PARAGRAPH [Node Nothing (TEXT "hi") []]]
"<p>hi[\aB</p>\n"
Prelude CMarkGFM> nodeToHtml [] [] $ Node Nothing DOCUMENT [Node Nothing PARAGRAPH [Node Nothing (TEXT "hi") []]]
"<p>hio\EOTB</p>\n"
@jgm
Copy link
Owner Author

jgm commented Mar 13, 2019

We need that null terminator!

@jgm jgm closed this as completed in d2c636f Mar 13, 2019
@jgm
Copy link
Owner Author

jgm commented Mar 13, 2019

@kivikakk can you cherry-pick this change for cmark-gfm-hs and make a new release?
It seems to fix the issue.
EDIT: You will also need 15041a8

@andersk
Copy link
Contributor

andersk commented Mar 13, 2019

Good catch, that was silly of me. I’ve proposed the addition of withCString to Data.Text in haskell/text#254.

@jgm
Copy link
Owner Author

jgm commented Mar 13, 2019 via email

@kivikakk
Copy link

Thanks for the update again! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants