Skip to content

[Console] Escape pipes and newlines in markdown tables - #66942

Merged
nicolas-grekas merged 1 commit into
symfony:7.4from
lazerg:fix/issue-66941-markdown-table-escaping
Oct 14, 2026
Merged

nicolas-grekas merged 1 commit into
symfony:7.4from
lazerg:fix/issue-66941-markdown-table-escaping

Conversation

@lazerg

@lazerg lazerg commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor
Q A
Branch? 7.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #66941
License MIT

The markdown table style writes cell content as is. A | in a cell opens an extra column, and a newline in a cell is split into a second table row, so the output is no longer valid markdown.

The table now escapes cells when the markdown style is in use: | becomes \|, and \n, \r\n or \r becomes <br>. A backslash before a line break is doubled, so that markdown does not read \<br> as an escaped <. This happens in buildTableRows(), after setColumnMaxWidth() wraps the cell and before the column widths are computed, so the padding stays aligned. With the markdown style, wrapped lines also become <br> instead of extra rows. Colspan and cell styles are kept.

| Name    | Description      |
|---------|------------------|
| pipe    | A \| B           |
| newline | Line 1<br>Line 2 |

I added a case to renderProvider that fails without the fix. ./phpunit src/Symfony/Component/Console passes, except two QuestionHelperTest failures that also happen on 7.4 without this change in my local environment. The patch also applies cleanly to 8.2.

@lazerg

lazerg commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

The Fabbot failure is a codespell false positive. It flags the author name "Max Grigorian" in the Table.php header, a line this PR does not change, so I left it as is.

@nicolas-grekas

Copy link
Copy Markdown
Member

Thanks @lazerg. I squashed a fix into your commit. The escaping now runs after setColumnMaxWidth() wraps the cell. Before, abcd|efgh at width 5 gave abcd\ on one row and |efgh on the next one. Wrapped lines now become <br> too, so a markdown cell never spans several rows.

I kept your backslash case, but the backslash is now doubled. With Line 1\<br>, markdown reads \< as an escaped < and shows <br> as text. A lone \r also becomes <br> now.

@nicolas-grekas

Copy link
Copy Markdown
Member

Thank you @lazerg.

@nicolas-grekas
nicolas-grekas merged commit d3584fb into symfony:7.4 Oct 14, 2026
13 of 15 checks passed
nicolas-grekas added a commit that referenced this pull request Oct 18, 2026
…kas)

This PR was merged into the 6.4 branch.

Discussion
----------

Add "grigorian" to the codespell ignore list

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Fabbot's codespell step reads the ``@author` Max Grigorian` line of Console's `Table` helper as a typo (`Grigorian ==> Gregorian`), so every PR that touches this file gets a red check, as #66942, #67092 and #67128 did.

Commits
-------

bc92e25 Add "grigorian" to the codespell ignore list
This was referenced Oct 28, 2026
amenk added a commit to iMi-digital/shopware that referenced this pull request Nov 3, 2026
Symfony 7.4.22 escapes pipes and line breaks in the markdown table style
itself (symfony/symfony#66942), so the escaping in
renderFormattedTable() is no longer needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants