File tree 2 files changed +12
-1
lines changed
2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -120,7 +120,7 @@ def sanitize(html, options = {})
120
120
loofah_fragment . scrub! ( :strip )
121
121
end
122
122
123
- loofah_fragment . to_s
123
+ properly_encode ( loofah_fragment , encoding : 'UTF-8' )
124
124
end
125
125
126
126
def sanitize_css ( style_string )
@@ -136,6 +136,10 @@ def allowed_tags(options)
136
136
def allowed_attributes ( options )
137
137
options [ :attributes ] || self . class . allowed_attributes
138
138
end
139
+
140
+ def properly_encode ( fragment , options )
141
+ fragment . xml? ? fragment . to_xml ( options ) : fragment . to_html ( options )
142
+ end
139
143
end
140
144
end
141
145
end
Original file line number Diff line number Diff line change @@ -441,6 +441,13 @@ def test_x03a_legitimate
441
441
assert_sanitized %(<a href="http://legit">) , %(<a href="http://legit">)
442
442
end
443
443
444
+ def test_sanitize_ascii_8bit_string
445
+ white_list_sanitize ( '<a>hello</a>' . encode ( 'ASCII-8BIT' ) ) . tap do |sanitized |
446
+ assert_equal '<a>hello</a>' , sanitized
447
+ assert_equal Encoding ::UTF_8 , sanitized . encoding
448
+ end
449
+ end
450
+
444
451
protected
445
452
446
453
def xpath_sanitize ( input , options = { } )
You can’t perform that action at this time.
0 commit comments