Handle empty frontmatter in local helpers#59
Open
fa1k3 wants to merge 2 commits into
Open
Conversation
The empty-frontmatter regex used the /m flag, so the opening `^---` could match a `---` line mid-body. splice() slices via m[0].length assuming the match starts at index 0, so a note with no frontmatter but `---` lines in the body (thematic breaks) was mis-parsed and its content silently corrupted. Anchor the opening `---` to string start (drop /m) and make the content group optional so an empty block (`---\n---\n`) still matches. Add a regression test for the no-frontmatter / body-`---` case. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
|
Updated: rebased onto |
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.
Summary
---\n---\n) in the local frontmatter helpers/mflag) so---lines in the body (thematic breaks) are never mistaken for a frontmatter block---\n---when adding frontmatter tags to a note with an empty block---linesWhy
The composed tag/frontmatter helpers read and rewrite raw note content for operations that have no single Local REST API equivalent. The matcher missed valid empty frontmatter blocks.
A multiline-anchored fix would over-match: with
/m, the opening^---can match a---line mid-body, and becausesplice()slices viam[0].length(assuming the match is at index 0), a note with no frontmatter but---lines in the body would be silently corrupted. The matcher is therefore anchored to string start with an optional content group — this handles the empty block without the false positive.Tests
bun test tests/services/frontmatter-ops.test.tsbun run test(full suite green)bun run test:types