File: test_attributes_properly_escaped.rb

package info (click to toggle)
ruby-nokogiri 1.11.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,576 kB
  • sloc: xml: 28,086; ruby: 18,456; java: 13,067; ansic: 5,138; yacc: 265; sh: 208; makefile: 27
file content (34 lines) | stat: -rwxr-xr-x 1,129 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require "helper"

module Nokogiri
  module HTML
    class TestAttributesProperlyEscaped < Nokogiri::TestCase
      unless Nokogiri::VersionInfo.instance.libxml2? && Nokogiri::VersionInfo.instance.libxml2_using_system?

        def test_attribute_macros_are_escaped
          html = "<p><i for=\"&{<test>}\"></i></p>"
          document = Nokogiri::HTML::Document.new
          nodes = document.parse(html)

          assert_equal("<p><i for=\"&amp;{&lt;test&gt;}\"></i></p>", nodes[0].to_s)
        end

        def test_libxml_escapes_server_side_includes
          original_html = %(<p><a href='<!--"><test>-->'></a></p>)
          document = Nokogiri::HTML::Document.new
          html = document.parse(original_html).to_s

          assert_match(/!--%22&gt;&lt;test&gt;/, html)
        end

        def test_libxml_escapes_server_side_includes_without_nested_quotes
          original_html = %(<p><i for="<!--<test>-->"></i></p>)
          document = Nokogiri::HTML::Document.new
          html = document.parse(original_html).to_s

          assert_match(/&lt;!--&lt;test&gt;/, html)
        end
      end
    end
  end
end