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