Ignore a leading thematic break that isn't really frontmatter - #215
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
`/\A---\s*(.*?)\s*---\s*(.*)/m` also matches a post whose body opens with
a `---` thematic break and has another `---` further down. `YAML.safe_load`
then returns a string (or an array) rather than a mapping, and
`Separator#frontmatter` calls `.each` on it:
Perron::Resource::Separator.new("---\nintro\n---\nbody").frontmatter
# => NoMethodError: undefined method 'each' for an instance of String
Only treat the fenced block as frontmatter when it parses to a `Hash`
(or to `nil`, i.e. empty frontmatter); otherwise the whole document is
content.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GtYgwYNfJ3wHrw9xrooVoB
Author
|
CI is on |
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.
The bug
Separatorsplits frontmatter from content with/\A---\s*(.*?)\s*---\s*(.*)/m. That regex also matches a post whose body starts with a---thematic break and contains another---:YAML.safe_loadparses"An intro paragraph."to aString, so@frontmatteris a string, andSeparator#frontmatterdoes@frontmatter.each { |key, value| ... }:A YAML list between the fences is nearly as bad — it silently produces
{item: nil, ...}.The fix
Only treat the fenced block as frontmatter when it parses to a
Hash(or tonil— empty frontmatter, already supported). Anything else means the leading---was content.Tests
Two cases added to
separator_test.rb— a leading thematic break, and a bare scalar between the fences. Both fail onmain(NoMethodError, and content mis-split).bundle exec rakeis green (403 runs, 0 failures;standardrbclean).🤖 Generated with Claude Code