Elm Exactly
Results / elm-url /

UrlIssue54PercentEncodeLoneSurrogateTest

Tags:elm19-bug

elm-0.19.1 failelm-0.19.2 failelm-0.19.3 faillamdera-1.5.0 fail

Issue: elm/url#54

`Url.percentEncode` throws on a lone surrogate.

<https://github.com/elm/url/issues/54>

Elm 0.19.1 (elm/url 1.0.0) calls `encodeURIComponent` unguarded, which throws `URIError: URI
malformed` for "\u{d800}" (a valid Elm String). `percentEncode : String -> String` must return a
string (`percentDecode` already catches the same exception).

This test is probably wrong under A Standard Definition of Elm? It writes the lone surrogate as
the escape `"\u{d800}"`, which ruling A8 makes invalid: an escape must denote a Unicode scalar
value. <https://elm-test-suite.netlify.app/standard/restrictions/core-escape-unicode> Under A8 the program does not compile, so a
compiler that follows the book fails this test without reaching the bug. `elm-url`'s
`UrlPercentEncodeLoneSurrogateTest` tests the same bug with the lone surrogate computed by
`Char.fromCode`. The test is kept as it is because it is the issue's program.

Results

elm-0.19.1

failran in 37 ms
exit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:3944
	return encodeURIComponent(string);
	       ^

URIError: URI malformed
    at encodeURIComponent (<anonymous>)
    at _Url_percentEncode (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:3944:9)
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:4457:4
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:4459:2
    at Object.<anonymous> (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:4460:160)
    at Module._compile (node:internal/modules/cjs/loader:1781:14)
    at Object..js (node:internal/modules/cjs/loader:1913:10)
    at Module.load (node:internal/modules/cjs/loader:1505:32)
    at Function._load (node:internal/modules/cjs/loader:1309:12)
    at wrapModuleLoad (node:internal/modules/cjs/loader:254:19)

Node.js v22.23.5

elm-0.19.2

failran in 64 ms
exit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:3944
	return encodeURIComponent(string);
	       ^

URIError: URI malformed
    at encodeURIComponent (<anonymous>)
    at _Url_percentEncode (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:3944:9)
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:4457:4
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:4459:2
    at Object.<anonymous> (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:4460:160)
    at Module._compile (node:internal/modules/cjs/loader:1781:14)
    at Object..js (node:internal/modules/cjs/loader:1913:10)
    at Module.load (node:internal/modules/cjs/loader:1505:32)
    at Function._load (node:internal/modules/cjs/loader:1309:12)
    at wrapModuleLoad (node:internal/modules/cjs/loader:254:19)

Node.js v22.23.5

elm-0.19.3

failran in 59 ms
exit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:3944
	return encodeURIComponent(string);
	       ^

URIError: URI malformed
    at encodeURIComponent (<anonymous>)
    at _Url_percentEncode (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:3944:9)
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:4457:4
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:4459:2
    at Object.<anonymous> (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:4460:160)
    at Module._compile (node:internal/modules/cjs/loader:1781:14)
    at Object..js (node:internal/modules/cjs/loader:1913:10)
    at Module.load (node:internal/modules/cjs/loader:1505:32)
    at Function._load (node:internal/modules/cjs/loader:1309:12)
    at wrapModuleLoad (node:internal/modules/cjs/loader:254:19)

Node.js v22.23.5

lamdera-1.5.0

failran in 52 ms
exit code 1, expected 0
--- output ---
/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:5040
	return encodeURIComponent(string);
	       ^

URIError: URI malformed
    at encodeURIComponent (<anonymous>)
    at _Url_percentEncode (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:5040:9)
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:5527:4
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:5529:2
    at Object.<anonymous> (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-url/out/UrlIssue54PercentEncodeLoneSurrogateTest.js:5532:3)
    at Module._compile (node:internal/modules/cjs/loader:1781:14)
    at Object..js (node:internal/modules/cjs/loader:1913:10)
    at Module.load (node:internal/modules/cjs/loader:1505:32)
    at Function._load (node:internal/modules/cjs/loader:1309:12)
    at wrapModuleLoad (node:internal/modules/cjs/loader:254:19)

Node.js v22.23.5

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm-url/UrlIssue54PercentEncodeLoneSurrogateTest] in its title.

Source

The -- CHECK: lines give the expected output.

module UrlIssue54PercentEncodeLoneSurrogateTest exposing (main)
{-| `Url.percentEncode` throws on a lone surrogate.
<https://github.com/elm/url/issues/54>
Elm 0.19.1 (elm/url 1.0.0) calls `encodeURIComponent` unguarded, which throws `URIError: URI
malformed` for "\u{d800}" (a valid Elm String). `percentEncode : String -> String` must return a
string (`percentDecode` already catches the same exception).
This test is probably wrong under A Standard Definition of Elm? It writes the lone surrogate as
the escape `"\u{d800}"`, which ruling A8 makes invalid: an escape must denote a Unicode scalar
value. <https://elm-test-suite.netlify.app/standard/restrictions/core-escape-unicode> Under A8 the program does not compile, so a
compiler that follows the book fails this test without reaching the bug. `elm-url`'s
`UrlPercentEncodeLoneSurrogateTest` tests the same bug with the lone surrogate computed by
`Char.fromCode`. The test is kept as it is because it is the issue's program.
-}
-- TAGS: elm19-bug
-- CHECK: encoded:
import Html exposing (text)
import Url
main =
let
_ =
Debug.log "encoded" (String.length (Url.percentEncode "a\u{d800}b") > 0)
in
text "done"