From aad3a2c15ab484d1a0f6aa3e3953a33c452deb93 Mon Sep 17 00:00:00 2001 From: Alex Castillo Date: Wed, 9 Sep 2026 00:33:00 -0400 Subject: [PATCH] Insert the missing slash when making a relative path absolute `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 `` in rendered markdown -- produced `https://example.comcover.jpg`. That went straight into `og:image`, `twitter:image` and the feed `` rewrites. Join with a single `/`, tolerating a leading slash on the path. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01GtYgwYNfJ3wHrw9xrooVoB --- lib/perron/html_processor/absolute_urls.rb | 2 +- lib/perron/resource/metadata.rb | 2 +- test/perron/html_processor/absolute_urls_test.rb | 9 +++++++++ test/perron/resource/metadata_test.rb | 11 +++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/perron/html_processor/absolute_urls.rb b/lib/perron/html_processor/absolute_urls.rb index 6ce4c0f..40fe084 100644 --- a/lib/perron/html_processor/absolute_urls.rb +++ b/lib/perron/html_processor/absolute_urls.rb @@ -9,7 +9,7 @@ def process next if src.blank? || absolute_url?(src) - image["src"] = base_url + src + image["src"] = "#{base_url}/#{src.delete_prefix("/")}" end end diff --git a/lib/perron/resource/metadata.rb b/lib/perron/resource/metadata.rb index 4434734..5b7445b 100644 --- a/lib/perron/resource/metadata.rb +++ b/lib/perron/resource/metadata.rb @@ -71,7 +71,7 @@ def absolute_url(path) return path if path.blank? return path if path.start_with?("http://", "https://", "//") - Perron.configuration.url.delete_suffix("/") + path + "#{Perron.configuration.url.delete_suffix("/")}/#{path.delete_prefix("/")}" end def site_data diff --git a/test/perron/html_processor/absolute_urls_test.rb b/test/perron/html_processor/absolute_urls_test.rb index 3d8b4ef..85e8d83 100644 --- a/test/perron/html_processor/absolute_urls_test.rb +++ b/test/perron/html_processor/absolute_urls_test.rb @@ -60,4 +60,13 @@ def process_html(html) assert_dom_equal html, processed end + + test 'inserts a slash for a relative src without a leading slash' do + html = '' + processed = process_html(html) + + assert_dom_equal '' \ + '', + processed + end end diff --git a/test/perron/resource/metadata_test.rb b/test/perron/resource/metadata_test.rb index a4093e7..db94fda 100644 --- a/test/perron/resource/metadata_test.rb +++ b/test/perron/resource/metadata_test.rb @@ -105,6 +105,17 @@ def setup assert_equal 'Kendall', metadata.author, 'Frontmatter author should take highest precedence' end + test 'makes a relative frontmatter image absolute with a slash separator' do + metadata = Perron::Resource::Metadata.new( + resource: @post, + frontmatter: { image: 'cover.jpg' }, + collection: @posts_collection + ).data + + assert_equal 'http://localhost:3000/cover.jpg', metadata.image + assert_equal 'http://localhost:3000/cover.jpg', metadata.og_image + end + test 'removes nil values from final data after processing' do metadata = Perron::Resource::Metadata.new( resource: @about_page,