Skip to content

Don't crash on front matter with non-string mapping keys - #133

Closed
eeshsaxena wants to merge 1 commit into
eyeseast:mainfrom
eeshsaxena:fix/non-string-metadata-keys
Closed

Don't crash on front matter with non-string mapping keys#133
eeshsaxena wants to merge 1 commit into
eyeseast:mainfrom
eeshsaxena:fix/non-string-metadata-keys

Conversation

@eeshsaxena

Copy link
Copy Markdown

frontmatter.loads crashes on a document whose front matter has a non-string key:

>>> import frontmatter
>>> frontmatter.loads("---\n1: one\n---\nbody")
TypeError: keywords must be strings

Integers, booleans and dates are all valid YAML (and TOML) mapping keys, but loads builds the post with Post(content, handler, **metadata), and splatting a dict with a non-string key into keyword arguments raises TypeError: keywords must be strings, even though the front matter itself parsed fine.

The fix assigns the parsed metadata dict to the Post directly instead of splatting it, so non-string keys are preserved and round-trip through dumps/loads. String-key documents are unaffected. Added a test.

loads did Post(content, handler, **metadata), which raises
'keywords must be strings' when the parsed metadata has non-string keys.
Integers, booleans and dates are all valid YAML/TOML mapping keys, so a
document like '---\n1: one\n---' blew up even though the front matter is valid.
Assign the metadata dict to the Post directly instead of splatting it.
@eeshsaxena

Copy link
Copy Markdown
Author

Hi! Gentle nudge on this one whenever you have some bandwidth. It's a small, self-contained fix (Don't crash on front matter with non-string mapping keys), and it's currently mergeable with no conflicts. No urgency at all, and I'm happy to make any changes you'd like. Thanks for maintaining python-frontmatter!

@eeshsaxena

Copy link
Copy Markdown
Author

Closing this to clear out my older open PRs. Nothing wrong with the change on my side, I am just tidying up a backlog. If it is still useful to you, say so and I will reopen it and rebase it on current main.

@eeshsaxena eeshsaxena closed this Sep 6, 2026
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