Skip to content
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

Revert "Fix SI-5645 Don't escape quotes in PCDATA" #496

Merged
merged 1 commit into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
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
5 changes: 1 addition & 4 deletions jvm/src/test/scala/scala/xml/XMLTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,7 @@ class XMLTestJVM {
val inputStream = new java.io.ByteArrayInputStream(outputStream.toByteArray)
val streamReader = new java.io.InputStreamReader(inputStream, XML.encoding)

def unescapeQuotes(str: String) =
""".r.replaceFirstIn(str, "\"")
val xmlFixed = unescapeQuotes(xml.toString)
assertEquals(xmlFixed, XML.load(streamReader).toString)
assertEquals(xml.toString, XML.load(streamReader).toString)
}

@UnitTest
Expand Down
2 changes: 1 addition & 1 deletion shared/src/main/scala/scala/xml/Text.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Text(data: String) extends Atom[String](data) {
* specification.
*/
override def buildString(sb: StringBuilder): StringBuilder =
Utility.escapeText(data, sb)
Utility.escape(data, sb)
}

/**
Expand Down
14 changes: 0 additions & 14 deletions shared/src/main/scala/scala/xml/Utility.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,6 @@ object Utility extends AnyRef with parsing.TokenTests {
}
}

/**
* Appends escaped string to `s`, but not ".
*/
final def escapeText(text: String, s: StringBuilder): StringBuilder = {
val escTextMap = escMap - '"' // Remove quotes from escMap
text.iterator.foldLeft(s) { (s, c) =>
escTextMap.get(c) match {
case Some(str) => s ++= str
case _ if c >= ' ' || "\n\r\t".contains(c) => s += c
case _ => s // noop
}
}
}

/**
* Appends unescaped string to `s`, `amp` becomes `&`,
* `lt` becomes `<` etc..
Expand Down
20 changes: 2 additions & 18 deletions shared/src/test/scala/scala/xml/XMLTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,10 @@ class XMLTest {
@UnitTest
def escape =
assertEquals("""
"Come, come again, whoever you are, come!
"Come, come again, whoever you are, come!
Heathen, fire worshipper or idolatrous, come!
Come even if you broke your penitence a hundred times,
Ours is the portal of hope, come as you are."
Ours is the portal of hope, come as you are."
Mevlana Celaleddin Rumi""", <![CDATA[
"Come, come again, whoever you are, come!
Heathen, fire worshipper or idolatrous, come!
Expand Down Expand Up @@ -422,22 +422,6 @@ Ours is the portal of hope, come as you are."
assertHonorsIterableContract(<a a="" y={ null: String }/>.attributes)
}

@UnitTest
def t5645: Unit = {

val bar = "baz"
val script = <script type="text/javascript">
foo("{bar}");
</script>

val expected =
"""|<script type="text/javascript">
| foo("baz");
| </script>""".stripMargin

assertEquals(expected, script.toString)
}

@UnitTest
def t5843: Unit = {
val foo = scala.xml.Attribute(null, "foo", "1", scala.xml.Null)
Expand Down