diff --git a/lib/docs/core/filter.rb b/lib/docs/core/filter.rb index 70231648..c33a8d15 100644 --- a/lib/docs/core/filter.rb +++ b/lib/docs/core/filter.rb @@ -62,6 +62,12 @@ module Docs str[0] == '#' end + DATA_URL = 'data:'.freeze + + def data_url_string?(str) + str.start_with?(DATA_URL) + end + def relative_url_string?(str) !fragment_url_string?(str) && str !~ SCHEME_RGX end diff --git a/lib/docs/filters/core/normalize_urls.rb b/lib/docs/filters/core/normalize_urls.rb index 435eced2..98d8215d 100644 --- a/lib/docs/filters/core/normalize_urls.rb +++ b/lib/docs/filters/core/normalize_urls.rb @@ -11,9 +11,8 @@ module Docs def update_attribute(tag, attribute) css(tag.to_s).each do |node| - next if node[attribute].start_with?('data:image') next unless value = node[attribute] - next if fragment_url_string?(value) + next if fragment_url_string?(value) || data_url_string?(value) node[attribute] = normalize_url(value) end end diff --git a/test/lib/docs/filters/core/normalize_urls_test.rb b/test/lib/docs/filters/core/normalize_urls_test.rb index 9523ad1d..808c8635 100644 --- a/test/lib/docs/filters/core/normalize_urls_test.rb +++ b/test/lib/docs/filters/core/normalize_urls_test.rb @@ -74,6 +74,11 @@ class NormalizeUrlsFilterTest < MiniTest::Spec assert_equal @body, filter_output_string end + it "doesn't rewrite data image urls" do + @body = '' + assert_equal @body, filter_output_string + end + context "when context[:replace_paths] is a hash" do before do context[:base_url] = 'http://example.com/dir/'