From 76982c73c0df37ac79781ec1ef9518e08263a158 Mon Sep 17 00:00:00 2001 From: fauno Date: Fri, 11 Jul 2025 09:07:17 -0300 Subject: [PATCH] Do not treat colons in `url_placeholders` as URI delimiters (#9850) Merge pull request 9850 --- lib/jekyll/url.rb | 8 +++++++- test/test_url.rb | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/url.rb b/lib/jekyll/url.rb index aeb2ac0d..d57352c4 100644 --- a/lib/jekyll/url.rb +++ b/lib/jekyll/url.rb @@ -144,7 +144,13 @@ module Jekyll # pct-encoded = "%" HEXDIG HEXDIG # sub-delims = "!" / "$" / "&" / "'" / "(" / ")" # / "*" / "+" / "," / ";" / "=" - Addressable::URI.encode(path).encode("utf-8").sub("#", "%23") + # + # `Addressable::URI::CharacterClassesRegexps::PATH` is used to encode + # non-alphanumeric characters such as "[", "]", etc. + Addressable::URI.encode_component( + path, + Addressable::URI::CharacterClassesRegexps::PATH + ).encode("utf-8").sub("#", "%23") end # Unescapes a URL path segment diff --git a/test/test_url.rb b/test/test_url.rb index 859babd4..430789aa 100644 --- a/test/test_url.rb +++ b/test/test_url.rb @@ -80,5 +80,16 @@ class TestURL < JekyllUnitTest ).to_s end end + + should "not treat colons in placeholders as uri delimiters" do + assert_equal "/foo/foo%20bar:foobar/", URL.new( + :template => "/:x/:y/", + :placeholders => { :x => "foo", :y => "foo bar:foobar" } + ).to_s + end + + should "unescape urls with colons" do + assert_equal "/foo/foo bar:foobar/", Jekyll::URL.unescape_path("/foo/foo%20bar:foobar/") + end end end