filter relative_url should keep absolute urls with scheme/authority (#6490)
Merge pull request 6490
This commit is contained in:
parent
beed5513e4
commit
a66c4780cc
|
@ -20,13 +20,16 @@ module Jekyll
|
||||||
).normalize.to_s
|
).normalize.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
# Produces a URL relative to the domain root based on site.baseurl.
|
# Produces a URL relative to the domain root based on site.baseurl
|
||||||
|
# unless it is already an absolute url with an authority (host).
|
||||||
#
|
#
|
||||||
# input - the URL to make relative to the domain root
|
# input - the URL to make relative to the domain root
|
||||||
#
|
#
|
||||||
# Returns a URL relative to the domain root as a String.
|
# Returns a URL relative to the domain root as a String.
|
||||||
def relative_url(input)
|
def relative_url(input)
|
||||||
return if input.nil?
|
return if input.nil?
|
||||||
|
return input if Addressable::URI.parse(input.to_s).absolute?
|
||||||
|
|
||||||
parts = [sanitized_baseurl, input]
|
parts = [sanitized_baseurl, input]
|
||||||
Addressable::URI.parse(
|
Addressable::URI.parse(
|
||||||
parts.compact.map { |part| ensure_leading_slash(part.to_s) }.join
|
parts.compact.map { |part| ensure_leading_slash(part.to_s) }.join
|
||||||
|
|
|
@ -526,6 +526,21 @@ class TestFilters < JekyllUnitTest
|
||||||
filter = make_filter_mock({ "baseurl" => Value.new(proc { "/baseurl/" }) })
|
filter = make_filter_mock({ "baseurl" => Value.new(proc { "/baseurl/" }) })
|
||||||
assert_equal "/baseurl#{page_url}", filter.relative_url(page_url)
|
assert_equal "/baseurl#{page_url}", filter.relative_url(page_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "transform protocol-relative url" do
|
||||||
|
url = "//example.com/"
|
||||||
|
assert_equal "/base//example.com/", @filter.relative_url(url)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not modify an absolute url with scheme" do
|
||||||
|
url = "file:///file.html"
|
||||||
|
assert_equal url, @filter.relative_url(url)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not normalize absolute international URLs" do
|
||||||
|
url = "https://example.com/错误"
|
||||||
|
assert_equal "https://example.com/错误", @filter.relative_url(url)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "strip_index filter" do
|
context "strip_index filter" do
|
||||||
|
|
Loading…
Reference in New Issue