fix: treat a string passed to stringify as opaque content #190
Loading…
Reference in a new issue
No description provided.
Delete branch "spokodev/fix-stringify-string-content"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
matter.stringify(file, data)documents the string form offileas "The content string to append to stringified front-matter" (and "appending that to the given string"). But whenfileis a string it runsmatter(file), which parses the string as a document. If the body itself begins with the front-matter delimiter, that leading block is pulled out of the body and merged into the front matter — corrupting bothcontentanddata:A plain string (no leading delimiter) round-trips fine, so this is the documented happy path silently losing data, not misuse.
Fix
Wrap the string as
{ content: file, data: {} }instead of re-parsing it, so the body is appended verbatim under the new front matter. The emptydatakeepsstringify's existing no-data behaviour (a plain string with no data is returned unchanged). Object inputs and plain strings are unaffected.Test
Added an assertion that a content string starting with a delimiter is appended (not parsed) and round-trips with clean
data. It fails before the change and passes after; the full suite is green (76 passing).View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.