How to create xhtml query strings using Scala?

How to create an x ​​(ht) ml-Node containing an href attribute, including a query string, without & s being automatically escaped or a runtime error?

val text = Text("?key=val&key2=val2") 

will be shielded and

 val node = <a href="link?key=val&key2=val2">link</a> 

throws (in Scala 2.7.5):

 java.lang.AssertionError 

node will be used with the helper method Lift bind (), preferably with AttrBindParam ().

+4
source share
2 answers

to try:

 val text = scala.xml.Unparsed("link?key=val&key2=val2") val node = <a href={text}>link</a> 

But maybe you really mean:

 val node = <a href="link?key=val&amp;key2=val2">link</a> 

See Using ampersands in attribute values ​​(and elsewhere) in the XHTML 1.0 reference.

+5
source

The following will elude the ampersand:

 val node = <a href={"link?key=val&key2=val2"}>link</a> 

What maybe you really need.

+1
source

Source: https://habr.com/ru/post/1302234/


All Articles