Skip to content

fix: handle quotes, comments, and indented lines in frontmatter parser#4

Closed
Tokenized2027 wants to merge 2 commits intoleonprou:mainfrom
Tokenized2027:fix/frontmatter-parser-edge-cases
Closed

fix: handle quotes, comments, and indented lines in frontmatter parser#4
Tokenized2027 wants to merge 2 commits intoleonprou:mainfrom
Tokenized2027:fix/frontmatter-parser-edge-cases

Conversation

@Tokenized2027
Copy link
Copy Markdown
Contributor

What

Three surgical fixes to the hand-rolled YAML frontmatter parser in parse_frontmatter() (src/openstation/core.py). Zero new dependencies — stays true to the project's minimal philosophy.

Edge cases fixed

1. Quoted values not unquoted

Before: name: "my-task"'"my-task"' (quotes included in value)
After: name: "my-task"'my-task'

Works for both single and double quotes. Mismatched quotes (opening ≠ closing) are left untouched.

2. Comment lines silently poisoning the fields dict

Before: # this is a comment → key "# this is a comment" added to result
After: comment lines are skipped entirely

3. Indented list items treated as key-value pairs

Before: - subtask-1 → key " - subtask-1" with empty value added to result
After: lines starting with whitespace (space or tab) are skipped — parse_frontmatter_list() handles those separately, as it always has

New tests

tests/test_frontmatter.py — 26 test cases across 7 test classes:

  • TestStandardFrontmatter — regression tests for existing behaviour
  • TestColonValues — values containing colons (including URLs)
  • TestQuotedValues — single quotes, double quotes, mismatched, unquoted
  • TestCommentLines — full-line comments skipped, inline comments preserved
  • TestIndentedLines — space-indented and tab-indented lines skipped
  • TestEmptyFrontmatter — empty block, comment-only, blank-line-only
  • TestRealisticFrontmatter — full task and agent spec fixtures

Test results

All existing 416 tests pass. 26 new tests added, all passing.

(The 5 pre-existing failures in test_hooks.py are Windows shell-environment issues unrelated to this change — they fail identically on main.)

🤖 Generated with Claude Code

Tokenized2027 and others added 2 commits March 21, 2026 18:29
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Skip lines starting with '#' (YAML comments) so they don't pollute the
  parsed fields dict with comment text as keys
- Skip lines starting with whitespace (space or tab) so indented list
  items and continuation lines are ignored; parse_frontmatter_list()
  handles those separately
- Strip surrounding single or double quotes from scalar values so that
  'name: "my-task"' returns 'my-task' rather than '"my-task"'

All three changes are surgical: no new dependencies, no behaviour
changes for well-formed YAML that didn't hit these cases, and all
existing 416 tests still pass.

Add tests/test_frontmatter.py with 26 focused test cases covering
regression parity, colon-in-value, quoted values, comment skipping,
indented-line skipping, empty frontmatter blocks, and a realistic
mixed frontmatter fixture.
@leonprou
Copy link
Copy Markdown
Owner

Hey, thanks for the contribution! The diff looks larger than expected because the file was converted from LF to CRLF (Windows line endings) — every line shows as changed even though only a few lines actually differ.

Could you normalize the line endings back to LF? This should work on any OS:

git config core.autocrlf input
git rm --cached src/openstation/core.py
git add src/openstation/core.py
git commit -m "fix: normalize line endings to LF"

Also, if you're up for it, it'd be great to add a .gitattributes file to the repo root to prevent this from happening again:

* text=auto eol=lf

Once that's done the diff should be clean and easy to review. Thanks!

leonprou added a commit that referenced this pull request Mar 25, 2026
Apply fixes from PR #4 (Tokenized2027) with clean LF line endings:
- Skip YAML comment lines (starting with #) in parse_frontmatter()
- Skip indented lines (list continuations) instead of mishandling them
- Strip surrounding single/double quotes from frontmatter values
- Add .gitattributes to enforce LF line endings
- Add 26 new tests covering all edge cases

Co-Authored-By: Tokenized2027 <Tokenized2027@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@leon-hyper
Copy link
Copy Markdown

Merged manually into main via commit 05edca2. Applied the three parser fixes and 26 new tests with clean LF line endings (avoiding the CRLF whole-file diff). Added .gitattributes to prevent future line-ending issues. Thanks for the contribution!

1 similar comment
@leonprou
Copy link
Copy Markdown
Owner

Merged manually into main via commit 05edca2. Applied the three parser fixes and 26 new tests with clean LF line endings (avoiding the CRLF whole-file diff). Added .gitattributes to prevent future line-ending issues. Thanks for the contribution!

@leonprou leonprou closed this Mar 25, 2026
leonprou added a commit that referenced this pull request Mar 25, 2026
Apply fixes from PR #4 (Tokenized2027) with clean LF line endings:
- Skip YAML comment lines (starting with #) in parse_frontmatter()
- Skip indented lines (list continuations) instead of mishandling them
- Strip surrounding single/double quotes from frontmatter values
- Add .gitattributes to enforce LF line endings
- Add 26 new tests covering all edge cases

Co-Authored-By: Tokenized2027 <Tokenized2027@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
leonprou added a commit that referenced this pull request Mar 25, 2026
Reviewed and merged PR #4 frontmatter parser fixes with CRLF normalization
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.

3 participants