Fix handling of invalid iframe URLs

Fixes #590.
pull/602/merge
Thibaut Courouble 8 years ago
parent c42ef5dc29
commit ed5a5cadd9

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

@ -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 = '<img src="%">'
assert_equal '<img src="#">', filter_output_string
end
it "doesn't rewrite invalid iframe urls" do
@body = '<iframe src="%"></iframe>'
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

Loading…
Cancel
Save