www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22628] New: std.json.parseJSON's exception msg may be invalid


          Issue ID: 22628
           Summary: std.json.parseJSON's exception msg may be invalid
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: kdevel vogtner.de

import std.stdio;
import std.json;
import std.utf;

void main ()
   auto json = "\u00fc"c;
   writefln ("input: <%s>", json);
   try parseJSON (json, JSONOptions.strictParsing);
   catch (Exception e) {
      writeln (e.msg);
      validate (e.msg);

output (on a console in latin1 mode):

input: <Ì>
Unexpected character 'Ã'. (Line 1:1)
std.utf.UTFException .../linux/bin64/../../src/phobos/std/utf.d(1547): Invalid
UTF-8 sequence (at index 1)
.../../../src/phobos/std/utf.d:1637 pure dchar std.utf.decodeImpl!(true, 0,
const(char)[]).decodeImpl(const(char)[], ref ulong) [0x499975]
.../linux/bin64/../../src/phobos/std/utf.d:1186 pure  trusted dchar
std.utf.decode!(0, const(immutable(char)[])).decode(ref
const(immutable(char)[]), ref ulong) [0x4b8b1a]
.../linux/bin64/../../src/phobos/std/utf.d:2937 pure  safe void
std.utf.validate!(immutable(char)[]).validate(in immutable(char)[]) [0x4b8a32]
./json_unexpected_character.d:12 _Dmain [0x495cd2]


input: <Ì>
Unexpected character 'Ì'. (Line 1:1)

Dec 24 2021