Elm Exactly
Results / elm-url /

UrlPercentDecodeInvalidUtf8Test

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`Url.percentDecode` returns `Nothing` when the decoded bytes are not valid UTF-8, and decodes a
valid sequence.

The invalid inputs are a bad lead byte (`%FF`), a truncated sequence (`%E2%82`), an encoded
surrogate (`%ED%A0%80`) and an overlong form (`%C0%AF`); the valid one is the euro sign. A `Just`
is shown as the code points of its string (`ConformanceHelp.cps`).

Results

elm-0.19.1

passran in 48 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
bad lead FF: "Nothing"
truncated E282: "Nothing"
surrogate EDA080: "Nothing"
overlong C0AF: "Nothing"
valid euro: "Just [20AC]"

elm-0.19.2

passran in 60 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
bad lead FF: "Nothing"
truncated E282: "Nothing"
surrogate EDA080: "Nothing"
overlong C0AF: "Nothing"
valid euro: "Just [20AC]"

elm-0.19.3

passran in 55 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
bad lead FF: "Nothing"
truncated E282: "Nothing"
surrogate EDA080: "Nothing"
overlong C0AF: "Nothing"
valid euro: "Just [20AC]"

lamdera-1.5.0

passran in 65 ms
Output
bad lead FF: "Nothing"
truncated E282: "Nothing"
surrogate EDA080: "Nothing"
overlong C0AF: "Nothing"
valid euro: "Just [20AC]"

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module UrlPercentDecodeInvalidUtf8Test exposing (main)
{-| `Url.percentDecode` returns `Nothing` when the decoded bytes are not valid UTF-8, and decodes a
valid sequence.
The invalid inputs are a bad lead byte (`%FF`), a truncated sequence (`%E2%82`), an encoded
surrogate (`%ED%A0%80`) and an overlong form (`%C0%AF`); the valid one is the euro sign. A `Just`
is shown as the code points of its string (`ConformanceHelp.cps`).
-}
-- MODE-GUARD: a Char equality must give the same answer as under --optimize
-- NO-SKIP: an edge case every compiler must run
-- CHECK: bad lead FF: "Nothing"
-- CHECK: truncated E282: "Nothing"
-- CHECK: surrogate EDA080: "Nothing"
-- CHECK: overlong C0AF: "Nothing"
-- CHECK: valid euro: "Just [20AC]"
import ConformanceHelp exposing (cps, logAll, worker)
import Url
{-| Percent-decodes `s` and shows the result in ASCII.
-}
decoded : String -> String
decoded s =
case Url.percentDecode s of
Just v ->
"Just [" ++ cps v ++ "]"
Nothing ->
"Nothing"
report : ()
report =
logAll
[ ( "bad lead FF", decoded "%FF" )
, ( "truncated E282", decoded "%E2%82" )
, ( "surrogate EDA080", decoded "%ED%A0%80" )
, ( "overlong C0AF", decoded "%C0%AF" )
, ( "valid euro", decoded "%E2%82%AC" )
]
main : Program () () ()
main =
worker report