Skip code spans anywhere in a table cell, not just at its start - #364
Merged
Merged
Conversation
tableRow ran the code-span check once before its scan loop, so it only fired when a cell began with a backtick. tableHeader and tableFooter run the same check inside their scan loops. A cell whose code span starts later was split at the pipe inside it, and because the column count came from the header, the last cell was dropped. tableHeader only counts columns; it hands the header line to tableRow to split, so header rows were affected too. Move the check into the loop, matching the other two. The i < n guard goes away because the loop condition already asserts it.
Contributor
|
Thanks! |
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.
tableRowruns its code-span check once, before the scan loop (parser/block_table.go:32-37), so it only fires when a cell starts with a backtick.tableFooter(:97-103) andtableHeader(:140-146) run the identical check, comment and all, inside their scan loops.So a cell whose code span starts anywhere but the first character is split at the pipe inside it, and the last cell is dropped because the column count came from the header:
tableHeaderonly counts columns; it hands the header line totableRowto split (:278), so header rows are affected the same way.This moves the check into the loop. The
i < nguard goes away because the loop condition already asserts it.The behaviour was added in #217, whose body says "Check for a codespan in the table (header, row or footer) and simply skip to the end of it and resume scanning" - header and footer resume, the row never did. Every golden that PR added puts the code span at the start of a cell, which is why this survived. #195 is the original request.
Verification
go test -count=1 -run 'TestTable$' ., Go 1.26.3.md5sum parser/block_table.goon every row.parser/block_table.go2389f3e8HEADf2994f1ab8f6a10ei += isCodeinstead ofi += isCode - 19a956f46data[i] == ''` fast pathfe3a27d8'`'to'~'363b04beThe
i += isCoderow only dies on the third golden,| x`|`| z |. With the first two the byte after the code span is ordinary text, so both forms stop at the same pipe; the two disagree only when that byte is the delimiter.The fast-path row is a genuine equivalent mutant. For a non-backtick byte
codeSpansetsnb = 0(parser/inline.go:135), the delimiter loop never runs, andfBegin == fEnd == 0returns0atparser/inline.go:180-181, soisCode > 0is false either way. The guard saves a call per byte, andtableHeader/tableFooterboth keep it.Goldens go in
testdata/Table.tests, which is where #217 put its own.Gates as
.github/workflows/go.ymlruns them:go test . ./ast ./parser ./htmlall ok,go test -bench=BenchmarkReference -benchmempasses. Not run: CI pins Go 1.18.x and this box has 1.26.3 only.Disclosure: this change was written with AI assistance (Claude). The measurements above were reproduced and checked by me before opening this PR.