com-lihaoyi / scalatags

ScalaTags is a small XML/HTML construction library for Scala.
https://com-lihaoyi.github.io/scalatags/
MIT License
757 stars 117 forks source link

How should I create href with a space? #204

Closed OndrejSpanel closed 4 years ago

OndrejSpanel commented 4 years ago

Assume following code (the real code is used to access GitHub repository actions):

import scalatags.Text.all._

val html = a(
   href := s"""https://a.com/page?query=workflow:"Some Name"""",
   "Some Name Actions"
).render

The result seems to be:

<a href="https://a.com/page?query=workflow:&quot;CI Error&quot;">CI Error</a>

While Chrome accepts such links, I think it is not correct and some user agents (namely Flying Saucer library) reject such hrefs as "containing invalid characters" because of the space in the CI Error. I think space in this place should be encoding using + (plus sign).

How should I achieve a proper encoding of the href value?

Bathtor commented 4 years ago

URI generally does the right thing, I think.

OndrejSpanel commented 4 years ago

Am I supposed to encode the href value somehow, similar to what is done in how to encode href attribute in HTML ?

I supposed ScalaTags will do The Right Thing on its own, but perhaps it does not in this case.

OndrejSpanel commented 4 years ago

Am I supposed to encode the href value somehow,

It seems I am. I encode individual query parameters using java.net.URLEncoder.encode(q, "UTF-8")