fix: escape pipe characters in column titles#56
Closed
greymoth-jp wants to merge 1 commit into
Closed
Conversation
Cell values are escaped through `toCellText`, but column titles were emitted verbatim. A column `name` containing a pipe (or a key that keeps its pipe through the header-case transform) put an unescaped `|` in the header row, giving it more cells than the delimiter row. Per the GFM spec the table is then not recognized at all. Escape the resolved column title the same way cell values are escaped, via a shared `escapePipes` helper.
|
Hey @greymoth-jp, thanks for contributing! If you haven't read the contributing guide that outlines the process, you can do so here. Maintainers: once checks have passed, comment |
Author
|
Closing this to clean up my open PRs. It's a small change and not really worth taking up your review time. Sorry for the noise. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cell values are escaped through
toCellTextso a|becomes\|, and there is a test for it ("escapes pipe characters in cells by default"). Column titles skip that step:getColumnTitlereturns the suppliedname, thetoHeaderTitleresult, or the cased key verbatim. So a pipe in a column title lands in the header row unescaped:The header row now has two cells while the delimiter row has one. The GFM tables spec requires the header row to match the delimiter row in cell count, otherwise the block is not parsed as a table. Rendered through marked the whole table collapses into a paragraph. The same
"Min | Max"placed in a body cell comes out asMin \| Max, so the two paths disagree.Fix
Escape pipes in the resolved column title the same way cell values are escaped. I pulled the existing pipe escaping out of
toCellTextinto a smallescapePipeshelper so both the cell path and the title path use one routine. With the fix the example becomes:which parses as a one column table with the header
Min | Max.Tests
Added "escapes pipe characters in column titles by default" alongside the existing cell test. Reverting the change makes the new snapshot mismatch. Full suite passes (76), and oxlint, eslint, prettier and
tsc --noEmitare clean.