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

Characters unnecessarily escaped by toString method of XML elements #5645

Closed
scabug opened this issue Apr 3, 2012 · 4 comments
Closed

Characters unnecessarily escaped by toString method of XML elements #5645

scabug opened this issue Apr 3, 2012 · 4 comments

Comments

@scabug
Copy link

scabug commented Apr 3, 2012

If I generate some Javascript in my Scala code like this:

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

and the Javascript contains a double quote character (like in the example), it will appear as {noformat}"{noformat} when the XML is converted into a string by toString, and Firefox will reject this Javascript as having a syntax error.

I don't think it's simply a matter of needing to subsequently replace all of the quot entities with double quotes, either, because some of them might actually need to stay escaped (if they are inside attribute values).

@scabug
Copy link
Author

scabug commented Apr 3, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5645?orig=1
Reporter: Robin Green (greenrd)
Affected Versions: 2.8.1, 2.10.0-M2, 2.11.6

@scabug
Copy link
Author

scabug commented Apr 16, 2015

Kevin Meredith (kevinmeredith) said (edited on Apr 16, 2015 6:47:21 PM UTC):
For newbies (like me):

scala> val xml = """<script type="text/javascript">
     |      foo("{bar}");
     | </script>"""
xml: String =
<script type="text/javascript">
     foo("{bar}");
</script>

scala> scala.xml.XML.loadString(xml)
res5: scala.xml.Elem =
<script type="text/javascript">
     foo(&quot;{bar}&quot;);
</script>

Is the expected solution here that quotes not be escaped for particular cases - such as within <script>?

@scabug
Copy link
Author

scabug commented Apr 16, 2015

@som-snytt said:
All your xml issues are belong to scala-xml.

https://github.com/scala/scala-xml/blob/master/src/main/scala/scala/xml/Text.scala#L26

toString encodes, but text does not. Pick one. Or, I wonder if ScalaTags has special smarts for scripters, embedding in comments etc.

http://lihaoyi.github.io/scalatags/

@scabug
Copy link
Author

scabug commented Jun 6, 2015

@som-snytt said:
scala/scala-xml#57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant