Skip to content

Commit c416c4e

Browse files
ashawleyRogach
authored andcommitted
Add test for ISO-8859-1 defect found with XML.save in #121
Try to closely mimic bug in XML.save and XML.loadFile, but write tests that don't use the file system. Will fail in 1.0.6 and earlier: expected:<...klmnopqrstuvwxyz{|}~[ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ]</x>> but was:<...klmnopqrstuvwxyz{|}~[????????????????????????????????????????????????????????????????????????????????????????????????]</x>> Will be fixed in #122.
1 parent bcec742 commit c416c4e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

jvm/src/test/scala/scala/xml/XMLTest.scala

+23
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,29 @@ class XMLTestJVM {
300300
</wsdl:definitions>""", wsdlTemplate4("service4", () => "target4") toString)
301301
}
302302

303+
// Issue found with ISO-8859-1 in #121 that was fixed with UTF-8 default
304+
@UnitTest
305+
def writeReadNoDeclarationDefaultEncoding: Unit = {
306+
val chars = ((32 to 126) ++ (160 to 255)).map(_.toChar)
307+
val xml = <x>{ chars.mkString }</x>
308+
309+
// com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:
310+
// Invalid byte 1 of 1-byte UTF-8 sequence.
311+
// scala.xml.XML.save("foo.xml", xml)
312+
// scala.xml.XML.loadFile("foo.xml").toString)
313+
314+
val outputStream = new java.io.ByteArrayOutputStream
315+
val streamWriter = new java.io.OutputStreamWriter(outputStream, XML.encoding)
316+
317+
XML.write(streamWriter, xml, XML.encoding, false, null)
318+
streamWriter.flush
319+
320+
val inputStream = new java.io.ByteArrayInputStream(outputStream.toByteArray)
321+
val streamReader = new java.io.InputStreamReader(inputStream)
322+
323+
assertEquals(xml.toString, XML.load(streamReader).toString)
324+
}
325+
303326
@UnitTest
304327
def t0663 = {
305328
val src = scala.io.Source.fromString("<?xml version='1.0' encoding='UTF-8'?><feed/>")

0 commit comments

Comments
 (0)