Skip to content

Commit

Permalink
Merge pull request #6287 from jekyll/3.5-stable-backport-6280
Browse files Browse the repository at this point in the history
Backport to 3.5: Guard against type error in absolute url (#6280)
  • Loading branch information
parkr committed Aug 10, 2017
2 parents 69e541b + 6554fb2 commit 0ef2937
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/jekyll/filters/url_filters.rb
Expand Up @@ -10,10 +10,12 @@ module URLFilters
# Returns the absolute URL as a String.
def absolute_url(input)
return if input.nil?
return input if Addressable::URI.parse(input).absolute?
return input if Addressable::URI.parse(input.to_s).absolute?
site = @context.registers[:site]
return relative_url(input).to_s if site.config["url"].nil?
Addressable::URI.parse(site.config["url"] + relative_url(input)).normalize.to_s
return relative_url(input) if site.config["url"].nil?
Addressable::URI.parse(
site.config["url"].to_s + relative_url(input)
).normalize.to_s
end

# Produces a URL relative to the domain root based on site.baseurl.
Expand Down
10 changes: 10 additions & 0 deletions test/test_filters.rb
Expand Up @@ -423,6 +423,16 @@ def select; end
page_url = "http://example.com/"
assert_equal "http://example.com/", @filter.absolute_url(page_url)
end

should "transform the input URL to a string" do
page_url = "/my-page.html"
filter = make_filter_mock({ "url" => Value.new(proc { "http://example.org" }) })
assert_equal "http://example.org#{page_url}", filter.absolute_url(page_url)
end

should "not raise a TypeError when passed a hash" do
assert @filter.absolute_url({ "foo" => "bar" })
end
end

context "relative_url filter" do
Expand Down

0 comments on commit 0ef2937

Please sign in to comment.