Skip to content

Commit

Permalink
more tests for data uri mediatypes
Browse files Browse the repository at this point in the history
and update CHANGELOG with this feature and a thank-you.

Related to #101, #120.
  • Loading branch information
flavorjones committed Sep 24, 2017
1 parent 7917ee9 commit dfdee76
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Features:

* Added :noopener HTML scrubber (Thanks, @tastycode!)
* Support `data` URIs with the following media types: text/plain, text/css, image/png, image/gif, image/jpeg, image/svg+xml. #101, #120. (Thanks, @mrpasquini!)


Bugfixes:
Expand Down
18 changes: 18 additions & 0 deletions test/html5/test_sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ def test_should_allow_multi_word_data_attributes
input = %(<a href="data:#{data_uri_type}">foo</a>)
output = "<a href='data:#{data_uri_type}'>foo</a>"
check_sanitization(input, output, output, output)

input = %(<a href="data:#{data_uri_type};base64,R0lGODlhAQABA">foo</a>)
output = "<a href='data:#{data_uri_type};base64,R0lGODlhAQABA'>foo</a>"
check_sanitization(input, output, output, output)
end
end

Expand All @@ -153,6 +157,20 @@ def test_should_allow_multi_word_data_attributes
end
end

def test_should_disallow_other_uri_mediatypes
input = %(<a href="data:foo">foo</a>)
output = "<a>foo</a>"
check_sanitization(input, output, output, output)

input = %(<a href="data:image/xxx">foo</a>)
output = "<a>foo</a>"
check_sanitization(input, output, output, output)

input = %(<a href="data:image/xxx;base64,R0lGODlhAQABA">foo</a>)
output = "<a>foo</a>"
check_sanitization(input, output, output, output)
end


HTML5::WhiteList::SVG_ALLOW_LOCAL_HREF.each do |tag_name|
next unless HTML5::WhiteList::ALLOWED_ELEMENTS.include?(tag_name)
Expand Down

0 comments on commit dfdee76

Please sign in to comment.