History

Fix handling of invalid iframe URLs

Fixes #590.

Thibaut Courouble committed 9 years ago

Commit ed5a5ca1 parent c42ef5d2 files · +13 −3Browse files

Unified · Split

2 files
  1. lib/docs/filters/core/normalize_urls.rb +2 −2
  2. test/lib/docs/filters/core/normalize_urls_test.rb +11 −1
lib/docs/filters/core/normalize_urls.rb+2−2
@@ -15,7 +15,7 @@ module Docs · 14 unmodified lines
15 css(tag.to_s).each do |node|15 css(tag.to_s).each do |node|
16 next unless value = node[attribute]16 next unless value = node[attribute]
17 next if fragment_url_string?(value) || data_url_string?(value)17 next if fragment_url_string?(value) || data_url_string?(value)
18 node[attribute] = normalize_url(value)18 node[attribute] = normalize_url(value) || (tag == :iframe ? value : '#')
19 end19 end
20 end20 end
21 21
@@ -31,7 +31,7 @@ module Docs · 9 unmodified lines
31 31
32 url.to_s32 url.to_s
33 rescue URI::InvalidURIError33 rescue URI::InvalidURIError
34 '#'34 nil
35 end35 end
36 36
37 def to_absolute_url(str)37 def to_absolute_url(str)
test/lib/docs/filters/core/normalize_urls_test.rb+11−1
@@ -39,11 +39,21 @@ class NormalizeUrlsFilterTest < MiniTest::Spec · 38 unmodified lines
39 assert_equal link_to(context[:url]), filter_output_string39 assert_equal link_to(context[:url]), filter_output_string
40 end40 end
41 41
42 it "rewrites invalid relative urls" do42 it "rewrites invalid link urls" do
43 @body = link_to '%'43 @body = link_to '%'
44 assert_equal link_to('#'), filter_output_string44 assert_equal link_to('#'), filter_output_string
45 end45 end
46 46
47 it "rewrites invalid image urls" do
48 @body = '<img src="%">'
49 assert_equal '<img src="#">', filter_output_string
50 end
51
52 it "doesn't rewrite invalid iframe urls" do
53 @body = '<iframe src="%"></iframe>'
54 assert_equal @body, filter_output_string
55 end
56
47 it "repairs un-encoded spaces" do57 it "repairs un-encoded spaces" do
48 @body = link_to 'http://example.com/#foo bar '58 @body = link_to 'http://example.com/#foo bar '
49 assert_equal link_to('http://example.com/#foo%20bar'), filter_output_string59 assert_equal link_to('http://example.com/#foo%20bar'), filter_output_string