Skip to content

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

Merged
eelcoj merged 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix/separator-non-hash-frontmatter
Oct 12, 2026
Merged

eelcoj merged 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix/separator-non-hash-frontmatter

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

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

@pcbeingused333

Copy link
Copy Markdown
Contributor 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).

`/\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.
@eelcoj
eelcoj force-pushed the fix/separator-non-hash-frontmatter branch from 7f15fb3 to bc1a807 Compare October 12, 2026 09:39
@eelcoj
eelcoj merged commit 23b7efa into Rails-Designer:main Oct 12, 2026
3 checks passed
@eelcoj

eelcoj commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Thanks again for the tokens spent on this, @pcbeingused333. I cleaned up some left over comments.

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.

2 participants