Bug 1024302

Summary: perl-JSON-PP: produces invalid JSON
Product: Red Hat Enterprise Linux 7 Reporter: Florian Weimer <fweimer>
Component: perl-JSON-PPAssignee: perl-maint-list
Status: CLOSED NOTABUG QA Contact: BaseOS QE - Apps <qe-baseos-apps>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.0CC: ppisar
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-10-29 15:01:41 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On:    
Bug Blocks: 1024293    

Description Florian Weimer 2013-10-29 11:12:23 UTC
JSON:PP escapes "'" characters, which is not allowed according to RFC 4627 and will cause deserialization errors with other JSON implementations:

$ perl -Ilib -MJSON::PP -MData::Dumper -we "print Dumper(encode_json([\"<<'>>\"]))"
$VAR1 = '["<<\'>>"]';

(The documentation still refers to_json, which has been obsoleted, BTW.)

Comment 2 Petr Pisar 2013-10-29 15:01:41 UTC
The solidus escaping an apostrophe is result of Data::Dumper::Dumper(). The JSON::PP::encode_json() does not do that. See simpler case:

$ perl -MJSON::PP -e "print encode_json([qq{'}]), qq{\n}"
["'"]

Comment 3 Florian Weimer 2013-10-29 15:49:47 UTC
Ugh, sorry about that.  You are right, of course.  This part of the source code confused me:

    my %esc = (
        "\n" => '\n',
        "\r" => '\r',
        "\t" => '\t',
        "\f" => '\f',
        "\b" => '\b',
        "\"" => '\"',
        "\\" => '\\\\',
        "\'" => '\\\'',
    );

        $arg =~ s/([\x22\x5c\n\r\t\f\b])/$esc{$1}/g;

' is present in the hash, but not in the regular expression.