Repository navigation
fix(blocks): an empty subject ends its header in a space, and trim() took it - #2
Merged
Merged
Conversation
…took it
The block-boundary test matched HEADER_RE against line.trim(). HEADER_RE
requires `subject:\s+` ahead of the subject capture, and serializeHeader
interpolates the subject straight after "subject: ", so a message written
without a subject serialises to a line whose last character is that required
space and nothing after it. Trimming took it off, the line stopped matching,
and the header stopped opening a block: the message was served as the tail of
the message above it, over that sender's name, with nothing missing from disk
and no error anywhere. A file whose ONLY header is one of those produced no
blocks at all and rendered as an empty thread, which is the worse half.
Strip leading whitespace only. The trim was there to keep an INDENTED
well-formed header a boundary - a known departure from protocol section 4,
recorded as corpus case indented-pseudo-header - and replace(/^\s+/, "") keeps
exactly that while leaving the end of the line as the writer emitted it.
Red-then-green by hand, in both directions, because one direction would only
have shown that the new tests test something:
reverted to line.trim() the two empty-subject cases fail (2 blocks where
3 are expected, 0 where 1 is expected) and the
new corpus case fails with them
no stripping at all the indented-header pin fails alongside the
corpus deviation record for the same behaviour,
which is what makes that pin worth its line
The fixture is built by serializeHeader rather than typed out, and the test
asserts the line really does end in a space, because a trailing space in a
source file is one formatter away from disappearing and taking the regression
with it.
The corpus gains empty-subject-trailing-space. It has a sibling already, the
bare-label spelling, and the sibling could not have caught this: the answer
recorded for the application there is "no blocks", so a reader that stopped
recognising the spelled-with-a-space form too would leave it passing and say
nothing. Both implementations satisfy the new case as written; the CLI never
had the defect, since it matches the raw line and its own subject group needs
no whitespace before it. The indented-pseudo-header deviation text is corrected
in passing: it described the boundary test as line.trim().startsWith("## "),
which stopped being true two fixes ago, while the behaviour it records never
moved.
Test count 1819 -> 1824 in rig/expected.mjs and in the README's three
published figures, measured on this tree rather than remembered.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
simon-inkie
commented
Aug 17, 2026
Owner
Author
There was a problem hiding this comment.
Independent review outcome: clean. The leading-whitespace-only match preserves the existing indented-header behaviour while retaining the trailing space required for empty subjects. The regression coverage constructs the writer-produced header and exercises the full splitBlocks to parseBlock path. I would approve this change, but GitHub prevents the currently authenticated PR-author account from self-approving.
simon-inkie
added a commit
that referenced
this pull request
Aug 18, 2026
…took it (#2) The block-boundary test matched HEADER_RE against line.trim(). HEADER_RE requires `subject:\s+` ahead of the subject capture, and serializeHeader interpolates the subject straight after "subject: ", so a message written without a subject serialises to a line whose last character is that required space and nothing after it. Trimming took it off, the line stopped matching, and the header stopped opening a block: the message was served as the tail of the message above it, over that sender's name, with nothing missing from disk and no error anywhere. A file whose ONLY header is one of those produced no blocks at all and rendered as an empty thread, which is the worse half. Strip leading whitespace only. The trim was there to keep an INDENTED well-formed header a boundary - a known departure from protocol section 4, recorded as corpus case indented-pseudo-header - and replace(/^\s+/, "") keeps exactly that while leaving the end of the line as the writer emitted it. Red-then-green by hand, in both directions, because one direction would only have shown that the new tests test something: reverted to line.trim() the two empty-subject cases fail (2 blocks where 3 are expected, 0 where 1 is expected) and the new corpus case fails with them no stripping at all the indented-header pin fails alongside the corpus deviation record for the same behaviour, which is what makes that pin worth its line The fixture is built by serializeHeader rather than typed out, and the test asserts the line really does end in a space, because a trailing space in a source file is one formatter away from disappearing and taking the regression with it. The corpus gains empty-subject-trailing-space. It has a sibling already, the bare-label spelling, and the sibling could not have caught this: the answer recorded for the application there is "no blocks", so a reader that stopped recognising the spelled-with-a-space form too would leave it passing and say nothing. Both implementations satisfy the new case as written; the CLI never had the defect, since it matches the raw line and its own subject group needs no whitespace before it. The indented-pseudo-header deviation text is corrected in passing: it described the boundary test as line.trim().startsWith("## "), which stopped being true two fixes ago, while the behaviour it records never moved. Test count 1819 -> 1824 in rig/expected.mjs and in the README's three published figures, measured on this tree rather than remembered. Co-authored-by: Simon <simon@inkie.ink> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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.
The defect
isBlockHeaderLinematchedHEADER_REagainstline.trim().HEADER_RErequiressubject:\s+ahead of the subject capture, andserializeHeaderinterpolates the subject straight after"subject: ", so a message written without a subject serialises to a line whose last character is that required space and nothing after it..trim()took that space off, the line stopped matching, and the header stopped opening a block:Nothing was missing from disk and nothing errored in either case, so both failed silently on every read.
The fix
Strip leading whitespace only:
HEADER_RE.test(line.replace(/^\s+/, "")).The
.trim()was there to keep an indented well-formed header a boundary, a known departure from protocol section 4 recorded as corpus caseindented-pseudo-header.replace(/^\s+/, "")keeps exactly that behaviour and leaves the end of the line as the writer emitted it. The comment above the function is rewritten to describe what it now does; it previously explained the.trim()as a deliberate choice, which would have been the wrong thing to leave standing.Verification
Red-then-green by hand, in both directions, because one direction only shows the new tests test something:
line.trim()The fixture is built by
serializeHeaderrather than typed out, and the test asserts the line really does end in a space: a trailing space in a source file is one formatter away from vanishing and taking the regression with it.Full suite green on a clean tree: deck 1824 passed / 11 skipped / 88 files, base 38 / 0 / 4.
check:leaks,check:licence,check:boundaries,check:dashesandpnpm typecheckall clean;node rig/self-test.mjs77/77.Two things beyond the one-line fix, both deliberate
A corpus case,
empty-subject-trailing-space. There is already anempty-subjectcase for the bare-label spelling, and it could not have caught this: the answer recorded fordeckthere is "no blocks", so a reader that also stopped recognising the spelled-with-a-space form would have left it passing and said nothing. Both implementations satisfy the new case as written, and it is red fordeckbefore this fix. The CLI never had the defect: it matches the raw line and its own subject group needs no whitespace before it.The
indented-pseudo-headerdeviation text. It described the boundary test asline.trim().startsWith('## '), which stopped being true two fixes ago. The recorded behaviour never moved, only the explanation of it, so this is a correction to thereasonfield alone.Test count 1819 -> 1824 in
rig/expected.mjsand in the README's three published figures, measured rather than remembered.CI is red for reasons that predate this branch
Both failures reproduce identically on
mainand on #1, and neither involves the code here:test (22.x)/test (24.x): the runner has no ripgrep, so the fourdashes.test.tscases that shell out torgerror. What the runner measured is 1820 passing, which is this PR's new figure for a ripgrep-less machine to the digit, so the README's degraded numbers are corroborated by the run rather than only by arithmetic.guards: the leak-gate self-test and the leak gate both pass;gitleaksthen fails with403 Resource n 8000 ot accessible by integrationonGET /pulls/{n}/commits. The workflow'sGITHUB_TOKENhas nopull-requests: readon apull_requestevent. It has never passed on a PR; it passes onmainonly because apushevent never calls that endpoint.Not fixed here
check:leaks:messagesandcheck:leaks:historyare each red onmaintoday, one finding apiece, both predating this branch and unrelated to it: a company email address in the co-author trailer that the merge of #1 added, and the internal product name in the first draft ofCLAUDE.md, whose blob is still reachable from that same merge even though the file itself was corrected before it landed. Worth a look, but not something to fold into a reader fix.