File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 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 = {})
120120 loofah_fragment . scrub! ( :strip )
121121 end
122122
123- loofah_fragment . to_s
123+ properly_encode ( loofah_fragment , encoding : 'UTF-8' )
124124 end
125125
126126 def sanitize_css ( style_string )
@@ -136,6 +136,10 @@ def allowed_tags(options)
136136 def allowed_attributes ( options )
137137 options [ :attributes ] || self . class . allowed_attributes
138138 end
139+
140+ def properly_encode ( fragment , options )
141+ fragment . xml? ? fragment . to_xml ( options ) : fragment . to_html ( options )
142+ end
139143 end
140144 end
141145end
Original file line number Diff line number Diff line change @@ -446,6 +446,13 @@ def test_x03a_legitimate
446446 assert_sanitized %(<a href="http://legit">) , %(<a href="http://legit">)
447447 end
448448
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+
449456protected
450457
451458 def xpath_sanitize ( input , options = { } )
You can’t perform that action at this time.
0 commit comments