Last active
August 29, 2015 14:04
-
-
Save miyagawa/a95f69e23ecf2626933a to your computer and use it in GitHub Desktop.
JSON::PP with utf8 in perl 5.8.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> PLENV_VERSION=5.8.4 perl -I$HOME/dev/cpanminus/fatlib ~/tmp/json-pp-utf8.t | |
1..3 | |
# perl 5.008004 | |
ok 1 - parse OK {"a": "å"} | |
ok 2 - parse OK {"a": 1, "b" : "å"} | |
not ok 3 - parse OK {"a": 0, "b" : "å"} | |
# Failed test (/Users/miyagawa/tmp/json-pp-utf8.t at line 8) | |
# , or } expected while parsing object/hash, at character offset 7 (before ", "b" : "\x{c3}\x{a5}...") at /Users/miyagawa/tmp/json-pp-utf8.t line 7 | |
# Looks like you failed 1 tests of 3. | |
> PLENV_VERSION=5.8.5 perl -I$HOME/dev/cpanminus/fatlib ~/tmp/json-pp-utf8.t | |
1..3 | |
# perl 5.008005 | |
ok 1 - parse OK {"a": "å"} | |
ok 2 - parse OK {"a": 1, "b" : "å"} | |
not ok 3 - parse OK {"a": 0, "b" : "å"} | |
# Failed test (/Users/miyagawa/tmp/json-pp-utf8.t at line 8) | |
# , or } expected while parsing object/hash, at character offset 7 (before ", "b" : "\x{c3}\x{a5}...") at /Users/miyagawa/tmp/json-pp-utf8.t line 7 | |
# Looks like you failed 1 tests of 3. | |
> PLENV_VERSION=5.8.8 perl -I$HOME/dev/cpanminus/fatlib ~/tmp/json-pp-utf8.t | |
1..3 | |
# perl 5.008008 | |
ok 1 - parse OK {"a": "å"} | |
ok 2 - parse OK {"a": 1, "b" : "å"} | |
ok 3 - parse OK {"a": 0, "b" : "å"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use JSON::PP; | |
use Test::More tests => 3; | |
diag "perl $]"; | |
sub parse_ok { | |
eval { JSON::PP->new->decode($_[0]) }; | |
ok !$@, "parse OK $_[0]"; | |
diag $@ if $@; | |
} | |
my $u = "\xc3\xa5"; # U+00e5 in utf-8 | |
parse_ok qq({"a": "$u"}); | |
parse_ok qq({"a": 1, "b" : "$u"}); | |
parse_ok qq({"a": 0, "b" : "$u"}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment