equivalent-xml icon indicating copy to clipboard operation
equivalent-xml copied to clipboard

Detecting unescaped xml entities

Open demimismo opened this issue 11 years ago • 0 comments

equivalent-xml ignores unescaped XML entities. Try with this spec:

  it "should detect xml entities" do
    doc1 = "<doc xmlns='foo:bar'><first order='1'>Sam & Max</first><second>things</second></doc>"
    doc2 = "<doc xmlns='foo:bar'><first order='1'>Sam Max</first><second>things</second></doc>"
    expect(doc1).not_to be_equivalent_to(doc2)
  end

That fails because Nokogiri is not configured with STRICT or NOENT options (see here)

I'm not sure what would be the most appropriate behaviour. Using STRICT would break other specs, like the one where you're comparing HTML:

  context "(on fragments consisting of multiple nodes)" do
    it "should compare all nodes" do
      doc1 = "<h1>Headline</h1><h1>Headline</h1>"
      doc2 = "<h1>Headline</h1><h2>Headline2</h2>"
      expect(doc1).not_to be_equivalent_to(doc2)
    end
  end

So if you need equivalient-xml to handle invalid XML strings, you're left with NOENT. Unfortunately, I don't see any way to use parsing options with Nokogiri::XML#fragment (here), that's why I haven't opened a PR, sorry.

demimismo avatar Nov 29 '14 17:11 demimismo