From 3bd146fb2c66967b4ad2a3a3c8358ff7aee43ac0 Mon Sep 17 00:00:00 2001 From: "Aaron S. Hawley" Date: Fri, 11 Nov 2016 01:35:54 -0500 Subject: [PATCH] Add test for ISO-8859-1 defect found with XML.save in #121 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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{|}~[ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ]> but was:<...klmnopqrstuvwxyz{|}~[????????????????????????????????????????????????????????????????????????????????????????????????]> Will be fixed in #122. --- src/test/scala/scala/xml/XMLTest.scala | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/test/scala/scala/xml/XMLTest.scala b/src/test/scala/scala/xml/XMLTest.scala index c86184ffd..a3bf9ac83 100644 --- a/src/test/scala/scala/xml/XMLTest.scala +++ b/src/test/scala/scala/xml/XMLTest.scala @@ -631,6 +631,29 @@ expected closing tag of foo """, 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 = { chars.mkString } + + // 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("")