www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17553] New: std.json invalid utf8 sequence


          Issue ID: 17553
           Summary: std.json invalid utf8 sequence
           Product: D
           Version: D2
          Hardware: x86
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: andre s-e-a-p.de

It is possible to read a file into a string. JSONValue happily accepts this
string which contains binary data.
But the moment you want to get data using js.toString an exception is thrown:
core.exception.UnicodeException src\rt\util\utf.d(292): invalid UTF-8 sequence

import std.json;
import std.file: read;

void main()
    string s = cast(string) read(`C:\D\dmd2\windows\bin\dmd.exe`);
    JSONValue js = JSONValue(s);

    string s2 = js.toString; // this line will throw the exception

Jun 25 2017