kotlinx.html icon indicating copy to clipboard operation
kotlinx.html copied to clipboard

Issue with amp for get request parameters

Open vlipovetskii opened this issue 5 years ago • 9 comments
trafficstars

kotlinx.html adds amp and browser is not able to process invalid url

https://test.html?name1=value1&name2=value2 -> https://test.html?name1=value1&ampname2=value2

import kotlinx.html.a
import kotlinx.html.body
import kotlinx.html.html
import kotlinx.html.stream.appendHTML
import org.amshove.kluent.should contain
import org.amshove.kluent.should not contain
import org.junit.jupiter.api.Test

class HtmlTests {

@Test
fun `when a(a&b) then a href=a&b`() {

    val getUrl = "https://test.html?name1=value1&name2=value2"

    val a = StringBuilder().apply {
        appendHTML().html {
            body {
                a(getUrl)
            }
        }
    }

    println(a)

    a.`should not contain`("&amp")
    a.`should contain`(getUrl)

}
}

vlipovetskii avatar Apr 07 '20 13:04 vlipovetskii

Related to: https://github.com/Kotlin/kotlinx.html/issues/94

I also ran into this with:

link("http://asdf.com/?foo=bar&asdf=zxcv")

Which becomes:

<link href="http://asdf.com/?foo=bar&amp;asdf=zxcv"/>

jamesward avatar Aug 31 '20 19:08 jamesward

Why do you expect it to NOT be HTML escaped ?

spand avatar Sep 01 '20 12:09 spand

Because it shouldn't be :)

jamesward avatar Sep 01 '20 13:09 jamesward

Web applications frameworks (in my case Vaadin) parse correctly parameters in links like http://asdf.com/?foo=bar&asdf=zxcv and do not process with amp http://asdf.com/?foo=bar&asdf=zxcv"

@spand You can try with other frameworks and result will be the same.

vlipovetskii avatar Sep 01 '20 13:09 vlipovetskii

Wonderful arguments all around. Please refer to standards when claiming this library is not compliant.

spand avatar Sep 01 '20 14:09 spand

Which standard would you like to use:

  • https://www.ietf.org/rfc/rfc1738.txt
  • https://tools.ietf.org/html/rfc3986
  • https://tools.ietf.org/html/rfc3987
  • https://url.spec.whatwg.org/

jamesward avatar Sep 01 '20 14:09 jamesward

Why are you quoting URL standards when this issue is about encoding URLs in HTML?

Please see https://stackoverflow.com/questions/3705591/do-i-encode-ampersands-in-a-href for related discussions.

spand avatar Sep 01 '20 14:09 spand

Which standard would you like to use as a basis for your position?

jamesward avatar Sep 01 '20 14:09 jamesward