Skip to content

Ignore a leading thematic break that isn't really frontmatter - #215

Open
pcbeingused333 wants to merge 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix/separator-non-hash-frontmatter
Open

pcbeingused333 wants to merge 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix/separator-non-hash-frontmatter

Conversation

@pcbeingused333

Copy link
Copy Markdown

The bug

Separator splits 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 ---:

---

An intro paragraph.

---

The rest of the post.

YAML.safe_load parses "An intro paragraph." to a String, so @frontmatter is a string, and Separator#frontmatter does @frontmatter.each { |key, value| ... }:

Perron::Resource::Separator.new("---\nintro\n---\nbody").frontmatter
# => NoMethodError: undefined method `each' for an instance of String

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 to nil — 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 on main (NoMethodError, and content mis-split). bundle exec rake is green (403 runs, 0 failures; standardrb clean).

🤖 Generated with Claude Code

`/\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
@pcbeingused333

Copy link
Copy Markdown
Author

CI is on action_required (fork gate). Verified with bundle exec rake (Docker, Ruby 3.4): 403 runs, 0 failures, standardrb clean. The two new tests fail on main (NoMethodError: undefined method 'each' for an instance of String).

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