Class: Loofah::Scrubbers::Unprintable
- Inherits:
-
Loofah::Scrubber
- Object
- Loofah::Scrubber
- Loofah::Scrubbers::Unprintable
- Defined in:
- lib/loofah/scrubbers.rb
Overview
scrub!(:unprintable)
+:unprintable+ removes unprintable Unicode characters.
markup = "<p>Some text with an unprintable character at the end\u2028</p>"
Loofah.fragment(markup).scrub!(:unprintable)
=> "<p>Some text with an unprintable character at the end</p>"
You may not be able to see the unprintable character in the above example, but there is a
U+2028 character right before the closing </p> tag. These characters can cause issues if
the content is ever parsed by JavaScript - more information here:
http://timelessrepo.com/json-isnt-a-javascript-subset
Constant Summary
Constants inherited from Loofah::Scrubber
Loofah::Scrubber::CONTINUE, Loofah::Scrubber::STOP
Instance Attribute Summary
Attributes inherited from Loofah::Scrubber
Instance Method Summary collapse
-
#initialize ⇒ Unprintable
constructor
A new instance of Unprintable.
- #scrub(node) ⇒ Object
Methods inherited from Loofah::Scrubber
Constructor Details
#initialize ⇒ Unprintable
Returns a new instance of Unprintable.
265 266 267 |
# File 'lib/loofah/scrubbers.rb', line 265 def initialize @direction = :top_down end |
Instance Method Details
#scrub(node) ⇒ Object
269 270 271 272 273 274 |
# File 'lib/loofah/scrubbers.rb', line 269 def scrub(node) if node.type == Nokogiri::XML::Node::TEXT_NODE || node.type == Nokogiri::XML::Node::CDATA_SECTION_NODE node.content = node.content.gsub(/\u2028|\u2029/, '') end CONTINUE end |