Bug 1024302 - perl-JSON-PP: produces invalid JSON
Summary: perl-JSON-PP: produces invalid JSON
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: perl-JSON-PP
Version: 7.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: perl-maint-list
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On:
Blocks: 1024293
TreeView+ depends on / blocked
 
Reported: 2013-10-29 11:12 UTC by Florian Weimer
Modified: 2013-10-29 15:49 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2013-10-29 15:01:41 UTC
Target Upstream Version:


Attachments (Terms of Use)

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.


Note You need to log in before you can comment on or make changes to this bug.