Skip to content

Commit

Permalink
test: add coverage for entities
Browse files Browse the repository at this point in the history
see sparklemotion/nokogiri#2461 for background
  • Loading branch information
flavorjones committed Feb 21, 2022
1 parent f80055a commit f8c6249
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/integration/test_ad_hoc.rb
Expand Up @@ -315,5 +315,49 @@ def test_dont_remove_whitespace_between_tags

assert_equal(expected, actual.to_html)
end

describe "entities" do
it "handles & character" do
input = %{<div> this & that </div>}
expected = %{<div> this &amp; that </div>}
actual = Loofah.scrub_fragment(input, :escape)
assert_equal(expected, actual.to_html)
end

it "handles > character" do
input = %{<div> this > that </div>}
expected = %{<div> this &gt; that </div>}
actual = Loofah.scrub_fragment(input, :escape)
assert_equal(expected, actual.to_html)
end

it "handles < character" do
input = %{<div> this < that </div>}
expected = %{<div> this &lt; that </div>}
actual = Loofah.scrub_fragment(input, :escape)
assert_equal(expected, actual.to_html)
end

it "handles < character in an attribute" do
input = %{<div alt="this < that">wave</div>}
expected = %{<div alt="this &lt; that">wave</div>}
actual = Loofah.scrub_fragment(input, :escape)
assert_equal(expected, actual.to_html)
end

it "handles multiple < characters" do
input = %{<div> this <<</div>}
expected = %{<div> this &lt;&lt;</div>}
actual = Loofah.scrub_fragment(input, :escape)
assert_equal(expected, actual.to_html)
end

it "handles &lt; entity" do
input = %{<div> this &lt; that </div>}
expected = input
actual = Loofah.scrub_fragment(input, :escape)
assert_equal(expected, actual.to_html)
end
end
end
end

0 comments on commit f8c6249

Please sign in to comment.