Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Scala from escaping double quotes in XML unnecessarily

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 &quot; when the XML is converted into a string, and Firefox will reject this Javascript as having a syntax error.

How can I avoid this Javascript error, without removing &quot;s that are actually needed?

I'm using Play framework 1.2.4 with the Scala module 0.9.1, which requires Scala 2.8.1.

like image 676
Robin Green Avatar asked Apr 03 '12 13:04

Robin Green


1 Answers

would something like this work for you?

scala> val bar=scala.xml.Unparsed(""""hello"""")
bar: scala.xml.Unparsed = "hello"

scala> val x = <script type="text/javascript">foo({bar});</script>
x: scala.xml.Elem = <script type="text/javascript">foo("hello");</script>
like image 85
Paolo Falabella Avatar answered Nov 01 '22 23:11

Paolo Falabella