Skip to content

Recognise an opening delimiter with trailing whitespace or a leading BOM - #143

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/opening-delimiter-whitespace-bom
Sep 27, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/opening-delimiter-whitespace-bom

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #141

What was wrong

HasFrontmatter only matched a document that started with exactly --- followed by a newline. Closing delimiters already went through IsDelimiterLine, which allows trailing whitespace. So a header opened by --- or ---\t (often left behind by editors), or preceded by a BOM, was not recognised. ExtractFrontmatter returned null, and AddFrontmatter stacked a second header on top of the real one.

Change

  • HasFrontmatter skips a leading BOM (``) and checks the first line with IsDelimiterLine, so opening and closing delimiters follow the same rule. It still requires a line ending after the opening delimiter.
  • TrySplitFrontmatterBlocks skips the same BOM when it tests the opening line.
  • DetectNewLine and the ktsu.Extensions using are removed, because nothing uses them now.

Tests

DelimiterLineTests covers --- , ---\t and a BOM prefix across HasFrontmatter, ExtractFrontmatter/ExtractBody and AddFrontmatter. AddFrontmatter now merges into the existing header and no longer stacks a second one. There is also a test that a bare delimiter with no line ending is still not frontmatter.

  • With the fix reverted, the 9 new data-row cases fail. The other 154 tests pass.
  • With the fix, the full suite passes: 163/163.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KMqfUfzWj2Gmdz1EqYdnLe


Generated by Claude Code

…leading BOM

HasFrontmatter required the document to start with exactly "---" and a
newline, while closing delimiters already allowed trailing whitespace. A
header opened by "--- " or "---\t", or preceded by a byte order mark, was
therefore invisible, and AddFrontmatter stacked a second header above it.

The opening line now goes through IsDelimiterLine like every other
delimiter, after skipping a leading BOM, both in HasFrontmatter and in
the block splitter.

Fixes #141

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KMqfUfzWj2Gmdz1EqYdnLe
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HasFrontmatter misses an opening --- with trailing whitespace (or a leading BOM), so AddFrontmatter stacks a second header above the real one

1 participant