Skip to content

Add test for ISO-8859-1 defect found with XML.save in #121 #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/test/scala/scala/xml/XMLTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,29 @@ expected closing tag of foo
</wsdl:definitions>""", wsdlTemplate4("service4", () => "target4") toString)
}

// Issue found with ISO-8859-1 in #121 that was fixed with UTF-8 default
@UnitTest
def writeReadNoDeclarationDefaultEncoding: Unit = {
val chars = ((32 to 126) ++ (160 to 255)).map(_.toChar)
val xml = <x>{ chars.mkString }</x>

// com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:
// Invalid byte 1 of 1-byte UTF-8 sequence.
// scala.xml.XML.save("foo.xml", xml)
// scala.xml.XML.loadFile("foo.xml").toString)

val outputStream = new java.io.ByteArrayOutputStream
val streamWriter = new java.io.OutputStreamWriter(outputStream, XML.encoding)

XML.write(streamWriter, xml, XML.encoding, false, null)
streamWriter.flush

val inputStream = new java.io.ByteArrayInputStream(outputStream.toByteArray)
val streamReader = new java.io.InputStreamReader(inputStream)

assertEquals(xml.toString, XML.load(streamReader).toString)
}

@UnitTest
def t0663 = {
val src = scala.io.Source.fromString("<?xml version='1.0' encoding='UTF-8'?><feed/>")
Expand Down