Skip to content

Commit 7073667

Browse files
author
Simeon F. Willbanks
committed
Safely dup protocols by providing default hash
1 parent aa3fa37 commit 7073667

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/html/pipeline/sanitization_filter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def call
111111
# hash to the filter but defaults to WHITELIST constant value above.
112112
def whitelist
113113
whitelist = (context[:whitelist] || WHITELIST).dup
114-
whitelist[:protocols] = whitelist[:protocols].dup
114+
whitelist[:protocols] = (whitelist[:protocols] || {}).dup
115115
whitelist[:protocols]['a'] = (whitelist[:protocols]['a'] || {}).merge('href' => anchor_schemes)
116116
whitelist
117117
end

test/html/pipeline/sanitization_filter_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ def test_anchor_schemes_are_merged_with_other_anchor_restrictions
7777
assert_equal '<a href="something-weird://heyyy">Wat</a> is this', html
7878
end
7979

80+
def test_whitelist_from_full_constant
81+
stuff = '<a href="something-weird://heyyy" ping="more-weird://hiii">Wat</a> is this'
82+
filter = SanitizationFilter.new(stuff, :whitelist => SanitizationFilter::FULL)
83+
html = filter.call.to_s
84+
assert_equal 'Wat is this', html
85+
end
86+
8087
def test_script_contents_are_removed
8188
orig = '<script>JavaScript!</script>'
8289
assert_equal "", SanitizationFilter.call(orig).to_s

0 commit comments

Comments
 (0)