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 @@ -446,6 +446,13 @@ def test_x03a_legitimate
446
446
assert_sanitized %(<a href="http://legit">) , %(<a href="http://legit">)
447
447
end
448
448
449
+ def test_sanitize_ascii_8bit_string
450
+ white_list_sanitize ( '<a>hello</a>' . encode ( 'ASCII-8BIT' ) ) . tap do |sanitized |
451
+ assert_equal '<a>hello</a>' , sanitized
452
+ assert_equal Encoding ::UTF_8 , sanitized . encoding
453
+ end
454
+ end
455
+
449
456
protected
450
457
451
458
def xpath_sanitize ( input , options = { } )
You can’t perform that action at this time.
0 commit comments