in reply to JSON::XS (and JSON::PP) appear to generate invalid UTF-8 for character in range 127 to 255

The following program passes its tests for me, side-stepping the source code encoding:

use utf8; use 5.16.0; use Test::More; use Test::utf8; use JSON::XS; BEGIN { # damn it my $builder = Test::Builder->new; foreach (qw/output failure_output todo_output/) { binmode $builder->$_, ':encoding(UTF-8)'; } } foreach my $string ( 'Deliver \N{LEFT-POINTING DOUBLE ANGLE QUOTAT +ION MARK}French Bread\N{RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK}', + '日本国' ) { my $hashref = { value => $string }; is_sane_utf8 $string, "String: $string"; my $json = encode_json($hashref); is_sane_utf8 $json, "JSON: $json"; say STDERR $json; } diag ord('»'); done_testing;

On the Windows command line, I get ord('»') also as 187 for perl -wle "print ord('»')"... I'm not sure what to make of this, but I feel confirmed in my intention to have no characters above code 127 in my source code...

Thanks for introducing me to Test::utf8 - this feels useful when diagnosing mojibake issues.

  • Comment on Re: JSON::XS (and JSON::PP) appear to generate invalid UTF-8 for character in range 127 to 255
  • Select or Download Code