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

Error processing in container-phrasing.js with specific markup combination #63

Closed
4 tasks done
vnphanquang opened this issue Nov 2, 2024 · 3 comments
Closed
4 tasks done
Labels
💪 phase/solved Post is done

Comments

@vnphanquang
Copy link

vnphanquang commented Nov 2, 2024

Initial checklist

Affected packages and versions

[email protected], possibly [email protected]

Link to runnable example

https://github.com/vnphanquang/repro-mdast-util-to-markdown

Steps to reproduce

Reproduction

  1. Clone the repository: https://github.com/vnphanquang/repro-mdast-util-to-markdown
  2. Install dependencies (pnpm, yarn, npm)
  3. Run script: node index.js

More information

Note

this reproduction does involve mdast-util-gfm, however stack trace points to mdast-util-to-markdown.

Given this input:

<table>
  <tbody>
    <tr>
      <td>
        <p>Paragraph 1</p>
        <p>
          <em><strong>Paragraph 2</strong></em>
        </p>
      </td>
    </tr>
  </tbody>
</table>

I suspect the key troubling markup is at <em><strong>Paragraph 2</strong></em>. However, it does require an odd combination of being inside a table and also having multiple paragraphs in td to trigger the observed error.

From my test, skipping...

before === results[results.length - 1].slice(-1)

...produces a successful output. That is:

- results[results.length - 1].slice(-1)
+ results[results.length - 1]?.slice(-1)

However, I lack knowledge of the codebase to determine whether this change produces other false positive. Happy to open PR if given direction.

Expected behavior

Should output output.md

Actual behavior

Error thrown as observed in console:

[..truncated]/node_modules/.pnpm/[email protected]/node_modules/mdast-util-to-markdown/lib/util/container-phrasing.js:106
        before === results[results.length - 1].slice(-1)
                                               ^

TypeError: Cannot read properties of undefined (reading 'slice')
    at containerPhrasing ([..truncated]/node_modules/.pnpm/[email protected]/node_modules/mdast-util-to-markdown/lib/util/container-phrasing.js:106:48)
    at Object.containerPhrasingBound [as containerPhrasing] ([..truncated]/node_modules/.pnpm/[email protected]/node_modules/mdast-util-to-markdown/lib/index.js:138:10)
    at paragraph ([..truncated]/node_modules/.pnpm/[email protected]/node_modules/mdast-util-to-markdown/lib/handle/paragraph.js:16:23)
    at containerPhrasing ([..truncated]/node_modules/.pnpm/[email protected]/node_modules/mdast-util-to-markdown/lib/util/container-phrasing.js:50:11)
    at Object.containerPhrasingBound [as containerPhrasing] ([..truncated]/node_modules/.pnpm/[email protected]/node_modules/mdast-util-to-markdown/lib/index.js:138:10)
    at handleTableCell ([..truncated]/node_modules/.pnpm/[email protected]/node_modules/mdast-util-gfm-table/lib/index.js:216:25)
    at handleTableRowAsData ([..truncated]/node_modules/.pnpm/[email protected]/node_modules/mdast-util-gfm-table/lib/index.js:279:23)
    at handleTableAsData ([..truncated]/node_modules/.pnpm/[email protected]/node_modules/mdast-util-gfm-table/lib/index.js:255:23)
    at Object.handleTable ([..truncated]/node_modules/.pnpm/[email protected]/node_modules/mdast-util-gfm-table/lib/index.js:191:26)
    at Object.one [as handle] ([..truncated]/node_modules/.pnpm/[email protected]/node_modules/zwitch/index.js:108:17)

Affected runtime and version

[email protected]

Affected package manager and version

[email protected]

Affected OS and version

Linux 6.6 Arch Linux

Build and bundle tools

other (please specify in steps to reproduce)

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Nov 2, 2024
@vnphanquang vnphanquang changed the title Error Processing Error processing specific markup combination in container-phrasing.js Nov 2, 2024
@vnphanquang vnphanquang changed the title Error processing specific markup combination in container-phrasing.js Error processing in container-phrasing.js with specific markup combination Nov 2, 2024
@wooorm wooorm closed this as completed in b0a91ea Nov 4, 2024
@wooorm wooorm added the 💪 phase/solved Post is done label Nov 4, 2024
@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Nov 4, 2024
@wooorm
Copy link
Member

wooorm commented Nov 4, 2024

Thanks for the repro!

It’s a bit of a weird case: p in td, as that isn’t allowed in GFM markdown itself. But it’s fine in HTML.

Anyway, good to add a guard to that check indeed!

@wooorm
Copy link
Member

wooorm commented Nov 4, 2024

Released in https://github.com/syntax-tree/mdast-util-to-markdown/releases/tag/2.1.2!

@vnphanquang
Copy link
Author

Thanks a lot @wooorm. That was super quick 🎉

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

No branches or pull requests

2 participants