From 79588ddcccd5f423101b50c6712c42262a081fba Mon Sep 17 00:00:00 2001 From: "Aaron S. Hawley" Date: Tue, 15 Dec 2015 16:31:14 -0500 Subject: [PATCH] Fix #72 XMLEventReader does not handle ' properly * src/main/scala/scala/xml/Utility.scala: Uncomment apos in Escapes map. (escape): Add case for apos. * src/test/scala/scala/xml/pull/XMLEventReaderTest.scala (entityRefTest): Unit test from Fehmi Can Saglam --- src/main/scala/scala/xml/Utility.scala | 9 +++--- src/test/scala/scala/xml/UtilityTest.scala | 9 +++++- .../scala/xml/pull/XMLEventReaderTest.scala | 28 ++++++++++++++++++- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/main/scala/scala/xml/Utility.scala b/src/main/scala/scala/xml/Utility.scala index e9aa88de6..039bad3db 100755 --- a/src/main/scala/scala/xml/Utility.scala +++ b/src/main/scala/scala/xml/Utility.scala @@ -97,13 +97,11 @@ object Utility extends AnyRef with parsing.TokenTests { "lt" -> '<', "gt" -> '>', "amp" -> '&', - "quot" -> '"' - // enigmatic comment explaining why this isn't escaped -- - // is valid xhtml but not html, and IE doesn't know it, says jweb - // "apos" -> '\'' + "quot" -> '"', + "apos" -> '\'' ) val escMap = pairs map { case (s, c) => c -> ("&%s;" format s) } - val unescMap = pairs ++ Map("apos" -> '\'') + val unescMap = pairs } import Escapes.{ escMap, unescMap } @@ -123,6 +121,7 @@ object Utility extends AnyRef with parsing.TokenTests { case '>' => s.append(">") case '&' => s.append("&") case '"' => s.append(""") + case '\'' => s.append("'") case '\n' => s.append('\n') case '\r' => s.append('\r') case '\t' => s.append('\t') diff --git a/src/test/scala/scala/xml/UtilityTest.scala b/src/test/scala/scala/xml/UtilityTest.scala index eba631efb..07c0ebe31 100644 --- a/src/test/scala/scala/xml/UtilityTest.scala +++ b/src/test/scala/scala/xml/UtilityTest.scala @@ -35,7 +35,14 @@ class UtilityTest { def aposEscaping: Unit = { val z = '' val z1 = z.toString - assertEquals("''", z1) + assertEquals("''", z1) + } + + @Test + def quotEscaping: Unit = { + val z = "" + val z1 = z.toString + assertEquals("""", z1) } @Test diff --git a/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala b/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala index 6b66326da..89cc2a6fa 100644 --- a/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala +++ b/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala @@ -2,7 +2,7 @@ package scala.xml package pull import org.junit.Test -import org.junit.Assert.{assertFalse, assertTrue} +import org.junit.Assert.{assertEquals,assertFalse, assertTrue} import scala.io.Source import scala.xml.parsing.FatalError @@ -168,4 +168,30 @@ class XMLEventReaderTest { while(er.hasNext) er.next() er.stop() } + + @Test + def entityRefTest: Unit = { // SI-7796 + val source = Source.fromString(""'<>&") + val er = new XMLEventReader(source) + + assertTrue(er.next match { + case EvElemStart(_, "text", _, _) => true + case _ => false + }) + + val entities = Seq( + EvEntityRef("quot"), + EvEntityRef("apos"), + EvEntityRef("lt"), + EvEntityRef("gt"), + EvEntityRef("amp")) + + assertEquals(entities, er.take(entities.size).toSeq) + + assertTrue(er.next match { + case EvElemEnd(_, "text") => true + case _ => false + }) + assertTrue(er.isEmpty) + } }