Open
Description
Bytes.Decode.string
will decode bytes that are not valid utf8 and produces an nonsense string. Instead it should fail. Thanks @jhbrown94 for helping me verify this.
SSCCE
module Main exposing (main)
import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
import Bytes exposing (Bytes)
import Bytes.Decode as Decode
import Bytes.Encode as Encode
bytes : Bytes
bytes =
Encode.encode
(Encode.sequence [Encode.unsignedInt8 0xC0, Encode.unsignedInt8 0])
string : Maybe String
string =
Decode.decode (Decode.string 2) bytes
update : () -> () -> ()
update () () = ()
view : () -> Html never
view () =
div []
[ div [] [ text <| Debug.toString string ]
]
main : Program () () ()
main =
Browser.sandbox
{ init = ()
, view = view
, update = update
}
Prints
Just "\0"
Should Print
Nothing
Ellie
Confirmation that b"\xC0\x00"
is not unicode
Metadata
Metadata
Assignees
Labels
No labels