Skip to content

Detecting unescaped xml entities #30

@demimismo

Description

@demimismo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions