Skip to content

fix(frontmatter): handle quote characters inside unquoted inline-array values - #13

Open
hyun-oho wants to merge 1 commit into
tigerless-labs:mainfrom
hyun-oho:fix/frontmatter-inline-array-quote
Open

hyun-oho wants to merge 1 commit into
tigerless-labs:mainfrom
hyun-oho:fix/frontmatter-inline-array-quote

Conversation

@hyun-oho

@hyun-oho hyun-oho commented Sep 5, 2026

Copy link
Copy Markdown

Problem

The frontmatter dialect parses inline arrays (links: [a, b, c]) with a
single-pass state machine in _split_items. The quote-tracking loop
treats any quote character (' or ") as a toggle into/out of
quoted mode, even when the quote appears mid-value rather than at the
value boundary.

An unquoted value containing a quote character — it's for example —
enters quote mode on the apostrophe and never exits. Every subsequent
comma is then swallowed as part of the quoted string, so the array
collapses into a single broken item.

>>> frontmatter.parse("---\nlinks: [it's, done]\n---\nbody\n")
{'links': ['"it\'s, done"']}    # wrong: 1 item, includes the comma

The render path always wraps list items in quotes, so the round-trip
via render → parse happens to work. The bug surfaces when a front-
matter file is edited by hand (which the project encourages — the
files are the source of truth) and an unquoted value contains an
apostrophe or a double-quote character.

Fix

Track whether the cursor is at the start of a new value (right after
the opening bracket, a comma, or leading whitespace). Only enter quote
mode when a quote character appears at that position. A quote in the
middle of an unquoted value is now treated as a regular character.

>>> frontmatter.parse("---\nlinks: [it's, done]\n---\nbody\n")
{'links': ["it's", "done"]}     # correct: 2 items

Testing

Added tests/unit/test_frontmatter.py covering the parse / render
round-trip, the unquoted-apostrophe case, a quoted value that contains
the other quote type, and the existing scalar and empty-array paths.

$ python3 -m pytest tests/unit/test_frontmatter.py -v
10 passed in 0.17s

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.

1 participant