Skip to content

XMLStreaming doesn't convert XML character references (in attributes) #300

@westnordost

Description

@westnordost

XMLStreaming doesn't convert XML character references. Only tested for attributes, don't know about other places in the XML where XML character references could occur.

This unit test would currently fail:

@Test fun `writer converts character references in attributes`() {
  val buffer = StringBuilder()
  val writer = xmlStreaming.newWriter(buffer)
  writer.startTag("", "test", null)
  writer.attribute(null, "attr", null, "With\nlinefeed")
  writer.endTag("", "test", null)

  assertEquals(
    "<test attr=\"With&#10;linefeed\"></test>", // or hexadecimal: &#xA
    buffer.toString()
  )
}

instead, the result looks like this:

<test attr="With
linefeed"></test>

Additional information

This unit test does not fail

@Test fun `reader converts character references in attributes`() {
  val source = "<test attr=\"With&#10;linefeed\"></test>" // or hexadecimal: &#xA
  val reader = xmlStreaming.newReader(source)
  
  forEach { 
    if (it == START_ELEMENT && localName == "test") {
      assertEquals(
        "With\nlinefeed",
        getAttributeValue(null, "attr")!!
      )
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    indevThe issue is fixed/implemented in the dev branch

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions