Insert the missing slash when making a relative path absolute - #217
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
`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
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
Metadata#absolute_urlandHtmlProcessor::AbsoluteUrls#processboth build the URL withbase_url + path:base_urlhas no trailing slash, so a relative path without a leading slash loses the separator:image: cover.jpgin a post's frontmatter (orin markdown, which renders as<img src="cover.jpg">) then feeds a broken URL intoog: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 frontmatterimagebecomeshttp://localhost:3000/cover.jpg.absolute_urls_test.rb—<img src="photo.jpg">andsrc="nested/photo.jpg"get the slash. Both fail onmain.bundle exec rakeis green (403 runs, 0 failures;standardrbclean).🤖 Generated with Claude Code