Elm Exactly
Results / elm-bytes /

BytesIssue20InvalidUtf8StringTest

Tags:elm19-bug

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

Issue: elm/bytes#20

`Bytes.Decode.string` decodes invalid UTF-8 into a nonsense string.

<https://github.com/elm/bytes/issues/20>

The bytes `C0 00` are not UTF-8 (0xC0 is never valid; a lead byte must be followed by a
continuation byte). Elm 0.19.1 (elm/bytes 1.0.8) combines the bits anyway and returns
`Just "\0"` (code point 0). Decoding must fail (`Nothing`), or at least yield U+FFFD
replacement characters as a standard UTF-8 decoder does.

Results

elm-0.19.1

failran in 76 ms
Missing pattern: {{decoded: (Nothing|Just "�)}}
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
decoded: Just "\0"

elm-0.19.2

failran in 70 ms
Missing pattern: {{decoded: (Nothing|Just "�)}}
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
decoded: Just "\0"

elm-0.19.3

failran in 59 ms
Missing pattern: {{decoded: (Nothing|Just "�)}}
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
decoded: Just "\0"

lamdera-1.5.0

failran in 66 ms
Missing pattern: {{decoded: (Nothing|Just "�)}}
--- output ---
decoded: Just "\0"

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module BytesIssue20InvalidUtf8StringTest exposing (main)
{-| `Bytes.Decode.string` decodes invalid UTF-8 into a nonsense string.
<https://github.com/elm/bytes/issues/20>
The bytes `C0 00` are not UTF-8 (0xC0 is never valid; a lead byte must be followed by a
continuation byte). Elm 0.19.1 (elm/bytes 1.0.8) combines the bits anyway and returns
`Just "\0"` (code point 0). Decoding must fail (`Nothing`), or at least yield U+FFFD
replacement characters as a standard UTF-8 decoder does.
-}
-- TAGS: elm19-bug
-- CHECK: {{decoded: (Nothing|Just "�)}}
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
main =
let
bytes =
E.encode (E.sequence [ E.unsignedInt8 0xC0, E.unsignedInt8 0 ])
_ =
Debug.log "decoded" (D.decode (D.string 2) bytes)
in
text "done"