From d213949c5904a286a0c556c88f987b7c634ea3b6 Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Thu, 27 Jul 2017 16:33:42 -0400 Subject: [PATCH 1/2] call to_s on site.url before attempting to concatenate strings --- lib/jekyll/filters/url_filters.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/filters/url_filters.rb b/lib/jekyll/filters/url_filters.rb index 53b4e253c4b..8e7e5949724 100644 --- a/lib/jekyll/filters/url_filters.rb +++ b/lib/jekyll/filters/url_filters.rb @@ -13,7 +13,7 @@ def absolute_url(input) return input if Addressable::URI.parse(input).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 + 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. From 32e64306bad7fb9d2fe703d6dc5d2d09d47257d4 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 30 Jul 2017 14:28:02 -0400 Subject: [PATCH 2/2] Ensure Filters#absolute_url calls to_s on the URL config Also adds tests --- lib/jekyll/filters/url_filters.rb | 4 +++- test/test_filters.rb | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/filters/url_filters.rb b/lib/jekyll/filters/url_filters.rb index 8e7e5949724..6ededc956d1 100644 --- a/lib/jekyll/filters/url_filters.rb +++ b/lib/jekyll/filters/url_filters.rb @@ -13,7 +13,9 @@ def absolute_url(input) return input if Addressable::URI.parse(input).absolute? site = @context.registers[:site] return relative_url(input).to_s if site.config["url"].nil? - Addressable::URI.parse(site.config["url"].to_s + relative_url(input)).normalize.to_s + 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. diff --git a/test/test_filters.rb b/test/test_filters.rb index bb4aa79795b..e0eb2feee87 100644 --- a/test/test_filters.rb +++ b/test/test_filters.rb @@ -13,6 +13,16 @@ def initialize(opts = {}) end end + class Value + def initialize(value) + @value = value + end + + def to_s + @value.respond_to?(:call) ? @value.call : @value.to_s + end + end + def make_filter_mock(opts = {}) JekyllFilter.new(site_configuration(opts)).tap do |f| tz = f.site.config["timezone"] @@ -423,6 +433,12 @@ 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 end context "relative_url filter" do @@ -500,6 +516,12 @@ def select; end url << "foo" assert_equal "/front_matter.erb", page.url end + + should "transform the input baseurl to a string" do + page_url = "/my-page.html" + filter = make_filter_mock({ "baseurl" => Value.new(proc { "/baseurl/" }) }) + assert_equal "/baseurl#{page_url}", filter.relative_url(page_url) + end end context "strip_index filter" do