Skip to content

Insert the missing slash when making a relative path absolute - #217

Open
pcbeingused333 wants to merge 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix/absolute-url-missing-slash
Open

pcbeingused333 wants to merge 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix/absolute-url-missing-slash

Conversation

@pcbeingused333

Copy link
Copy Markdown

The bug

Metadata#absolute_url and HtmlProcessor::AbsoluteUrls#process both build the URL with base_url + path:

Perron.configuration.url.delete_suffix("/") + path        # Metadata
base_url + src                                            # AbsoluteUrls

base_url has no trailing slash, so a relative path without a leading slash loses the separator:

absolute_url("cover.jpg")  # => "https://example.comcover.jpg"

image: cover.jpg in a post's frontmatter (or ![](cover.jpg) in markdown, which renders as <img src="cover.jpg">) then feeds a broken URL into og:image, twitter:image, and the feed image rewrites. A leading-slash path (/cover.jpg) already worked.

The fix

Join with a single /, tolerating a leading slash on the path:

"#{base}/#{path.delete_prefix("/")}"

Tests

metadata_test.rb — a relative frontmatter image becomes http://localhost:3000/cover.jpg. absolute_urls_test.rb<img src="photo.jpg"> and src="nested/photo.jpg" get the slash. Both fail on main. bundle exec rake is green (403 runs, 0 failures; standardrb clean).

🤖 Generated with Claude Code

`Metadata#absolute_url` and `HtmlProcessor::AbsoluteUrls` both did
`base_url + path`. `base_url` has no trailing slash, so a relative path
without a leading slash -- `image: cover.jpg` in frontmatter, or
`<img src="cover.jpg">` in rendered markdown -- produced
`https://example.comcover.jpg`. That went straight into `og:image`,
`twitter:image` and the feed `<img>` rewrites.

Join with a single `/`, tolerating a leading slash on the path.

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. Both new tests fail on main (https://example.comcover.jpg / http://localhost:3000photo.jpg — no slash).

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