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

"break" nodes not handled and cause a TypeError exception #5

Closed
4 tasks done
staltz opened this issue May 3, 2021 · 5 comments · Fixed by #6
Closed
4 tasks done

"break" nodes not handled and cause a TypeError exception #5

staltz opened this issue May 3, 2021 · 5 comments · Fixed by #6
Labels
💪 phase/solved Post is done

Comments

@staltz
Copy link
Contributor

staltz commented May 3, 2021

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)

Affected packages and versions: nlcst-to-string >=2.0.4 (at least, maybe older too)

Steps to reproduce

If there are trailing whitespaces at the end of a line, it seems to get parsed as type: break in Markdown, which nlcst-to-string doesn't know how to convert to string.

Link to code example: https://codesandbox.io/s/remark-debug-forked-hh0ub?file=/src/index.js

Example AST subtree containing breaks:

[ { type: 'text',
    value: 'Mobile: @6RpN4Ztw3jLwzQtHl8XpnnR58LWZTAjwq2vvfyx7zkc=.ed25519',
    position: 
     { start: { line: 3, column: 1, offset: 53 },
       end: { line: 3, column: 62, offset: 114 },
       indent: [] } },
  { type: 'break',
    position: 
     { start: { line: 3, column: 62, offset: 114 },
       end: { line: 4, column: 1, offset: 117 },
       indent: [ 1 ] } },
  { type: 'text',
    value: 'Desktop: @lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519',
    position: 
     { start: { line: 4, column: 1, offset: 117 },
       end: { line: 4, column: 63, offset: 179 },
       indent: [] } },
  { type: 'break',
    position: 
     { start: { line: 4, column: 63, offset: 179 },
       end: { line: 5, column: 1, offset: 182 },
       indent: [ 1 ] } },
  { type: 'text',
    value: 'Pub: @5XaVcAJ5DklwuuIkjGz4lwm2rOnMHHovhNg7BFFnyJ8=.ed25519',
    position: 
     { start: { line: 5, column: 1, offset: 182 },
       end: { line: 5, column: 59, offset: 240 },
       indent: [] } } ]

Expected behavior

No crash or exception thrown in the JS engine. The stringification should complete and break nodes should be considered empty string.

Actual behavior

Uncaught JS exception:

[TypeError: Cannot read property 'length' of undefined]
@github-actions github-actions bot added the 👋 phase/new Post is being triaged automatically label May 3, 2021
@github-actions

This comment has been minimized.

@github-actions github-actions bot added 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels May 3, 2021
@staltz staltz mentioned this issue May 3, 2021
5 tasks
@wooorm
Copy link
Member

wooorm commented May 3, 2021

Hmm, might this be better suited for mdast-util-to-string? nlcst is natural language nodes (paragraph, sentence, word, etc), whereas mdast includes break? 🤔

@staltz
Copy link
Contributor Author

staltz commented May 3, 2021

Oh, I wasn't sure which part of the pipeline was responsible for this. I'm happy with whatever place you think is the best for the fix.

@wooorm
Copy link
Member

wooorm commented May 3, 2021

Can you try mdast-util-to-string and see if that works for your use case?

@wooorm wooorm closed this as completed in #6 May 4, 2021
wooorm pushed a commit that referenced this issue May 4, 2021
Closes GH-5.
Closes GH-6.

Reviewed-by: Titus Wormer <tituswormer@gmail.com>
@github-actions github-actions bot added 🤷 no/invalid This cannot be acted upon 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels May 4, 2021
@wooorm wooorm added 💪 phase/solved Post is done and removed 👎 phase/no Post cannot or will not be acted on 🤷 no/invalid This cannot be acted upon labels May 4, 2021
@wooorm
Copy link
Member

wooorm commented May 4, 2021

Released!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done
Development

Successfully merging a pull request may close this issue.

2 participants