diff --git a/lib/docs/filters/core/normalize_urls.rb b/lib/docs/filters/core/normalize_urls.rb index 3d0dc7bb..cd1888a8 100644 --- a/lib/docs/filters/core/normalize_urls.rb +++ b/lib/docs/filters/core/normalize_urls.rb @@ -15,7 +15,7 @@ module Docs css(tag.to_s).each do |node| next unless value = node[attribute] next if fragment_url_string?(value) || data_url_string?(value) - node[attribute] = normalize_url(value) + node[attribute] = normalize_url(value) || (tag == :iframe ? value : '#') end end @@ -31,7 +31,7 @@ module Docs url.to_s rescue URI::InvalidURIError - '#' + nil end def to_absolute_url(str) diff --git a/test/lib/docs/filters/core/normalize_urls_test.rb b/test/lib/docs/filters/core/normalize_urls_test.rb index 808c8635..7e2a56e5 100644 --- a/test/lib/docs/filters/core/normalize_urls_test.rb +++ b/test/lib/docs/filters/core/normalize_urls_test.rb @@ -39,11 +39,21 @@ class NormalizeUrlsFilterTest < MiniTest::Spec assert_equal link_to(context[:url]), filter_output_string end - it "rewrites invalid relative urls" do + it "rewrites invalid link urls" do @body = link_to '%' assert_equal link_to('#'), filter_output_string end + it "rewrites invalid image urls" do + @body = '' + assert_equal '', filter_output_string + end + + it "doesn't rewrite invalid iframe urls" do + @body = '' + assert_equal @body, filter_output_string + end + it "repairs un-encoded spaces" do @body = link_to 'http://example.com/#foo bar ' assert_equal link_to('http://example.com/#foo%20bar'), filter_output_string