Skip to content

Tables: tolerate trailing whitespace on rows; reject empty delimiter cells#247

Merged
dereuromark merged 1 commit into
masterfrom
fix/table-delimiter-trailing-whitespace
Jun 16, 2026
Merged

Tables: tolerate trailing whitespace on rows; reject empty delimiter cells#247
dereuromark merged 1 commit into
masterfrom
fix/table-delimiter-trailing-whitespace

Conversation

@dereuromark

Copy link
Copy Markdown
Contributor

Two table delimiter-row divergences where the PHP implementation was the outlier (carve-js and carve-rs agreed). Ported from carve-php commit 28d4c10.

1. Trailing whitespace on table rows

Trailing spaces or tabs after a row's closing pipe broke row recognition. A line like | a | followed by spaces, or a separator |---| followed by spaces, was not treated as a table row, so a table with a trailing-whitespace separator split into separate blocks and the separator rendered as a paragraph.

Trailing whitespace after the closing pipe is insignificant and is now stripped before the structural checks (isTableRow, isSeparatorRow, the cell parsers, and the BlockParser row loop).

2. Empty delimiter cell

A delimiter row with an empty cell (|---||) was wrongly accepted as a header separator. The detection used a character class that placed | inside it and so never validated per cell. It now splits the row into cells and requires each to be a delimiter cell (optional whitespace, optional leading colon, one or more dashes, optional trailing colon). An empty cell or any other content disqualifies the row, which then stays an ordinary data row.

Behavior now matches the JS and Rust implementations on these delimiter-row edge cases.

…cells

Two table delimiter-row divergences (carve-js and carve-rs agreed; the PHP
impl was the outlier), ported from carve-php commit 28d4c10:

1. Trailing whitespace after a row's closing pipe broke recognition. A line
   like `| a |` followed by spaces, or a separator `|---|` followed by spaces,
   was not treated as a table row, so a table with a trailing-whitespace
   separator split into separate blocks and the separator rendered as a
   paragraph. Trailing spaces/tabs after the closing pipe are now stripped
   before the structural checks (isTableRow, isSeparatorRow, the cell parsers,
   and the BlockParser row loop).

2. A delimiter row with an empty cell (`|---||`) was accepted as a header
   separator. isSeparatorRow used a character class that put `|` inside it and
   so never validated per cell. It now splits the row into cells and requires
   each to be a delimiter cell (optional whitespace, optional leading `:`, one
   or more `-`, optional trailing `:`); an empty cell or any other content
   disqualifies the row, which then stays an ordinary data row.

Behavior now matches the JS and Rust implementations on these delimiter-row
edge cases.
@dereuromark dereuromark added the bug Something isn't working label Jun 16, 2026
@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.05%. Comparing base (306e362) to head (8e8413f).

Files with missing lines Patch % Lines
src/Parser/Block/TableParser.php 85.71% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #247      +/-   ##
============================================
- Coverage     92.06%   92.05%   -0.01%     
- Complexity     3571     3576       +5     
============================================
  Files           107      107              
  Lines         10118    10131      +13     
============================================
+ Hits           9315     9326      +11     
- Misses          803      805       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dereuromark dereuromark merged commit 5cf4c4d into master Jun 16, 2026
4 of 6 checks passed
@dereuromark dereuromark deleted the fix/table-delimiter-trailing-whitespace branch June 16, 2026 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant