class Loofah::Scrubbers::Unprintable
scrub!(:unprintable)¶ ↑
:unprintable
removes unprintable Unicode characters.
markup = "<p>Some text with an unprintable character at the end\u2028</p>" Loofah.html5_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
Public Class Methods
new()
click to toggle source
# File lib/loofah/scrubbers.rb, line 341 def initialize # rubocop:disable Lint/MissingSuper @direction = :top_down end
Public Instance Methods
scrub(node)
click to toggle source
# File lib/loofah/scrubbers.rb, line 345 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