Skip to content

XML Parsing fails with unescaped ampersand in content (not tag) #71

@drsharp

Description

@drsharp

If I have XML like this:

<?xml version="1.0" encoding="UTF-8" ?>
<outer>
  <inner>
    <before>data before</before>
    <data>Some & More</data>
    <after>here is after</after>
  </inner>
</outer>

and try to parse it like this:

xml = File.read("bad.xml")
result = Nori.new.parse(xml)

I get this:

{
    "data" => "Some  More\n        here is after\n  \n"
}

Which is clearly wrong. If I change the & into & it parses just fine:

<?xml version="1.0" encoding="UTF-8" ?>
<outer>
  <inner>
    <before>data before</before>
    <data>Some &amp; More</data>
    <after>here is after</after>
  </inner>
</outer>
{
    "outer" => {
        "inner" => {
            "before" => "data before",
              "data" => "Some & More",
             "after" => "here is after"
        }
    }
}

Why can't I use a raw & in the content? That seems to be a bug, right?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions