Don't rewrite data URIs

pull/511/head
Thibaut Courouble 8 years ago
parent 8e2e150be1
commit 721adf8e21

@ -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

@ -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

@ -74,6 +74,11 @@ class NormalizeUrlsFilterTest < MiniTest::Spec
assert_equal @body, filter_output_string
end
it "doesn't rewrite data image urls" do
@body = '<img src="data:image/gif;base64,aaaa">'
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/'

Loading…
Cancel
Save