Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86429 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31363 invoked from network); 28 May 2015 18:53:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 May 2015 18:53:24 -0000 Authentication-Results: pb1.pair.com smtp.mail=jakub.php@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=jakub.php@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.173 as permitted sender) X-PHP-List-Original-Sender: jakub.php@gmail.com X-Host-Fingerprint: 209.85.223.173 mail-ie0-f173.google.com Received: from [209.85.223.173] ([209.85.223.173:34258] helo=mail-ie0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C3/83-01144-12467655 for ; Thu, 28 May 2015 14:53:22 -0400 Received: by ieczm2 with SMTP id zm2so45760585iec.1 for ; Thu, 28 May 2015 11:53:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:content-type; bh=EoESsw50pnPCObLx7OGRTGS23FknEaYraqUDdnQgc/g=; b=gt8xBG8fpS+I/K7DRuOgHKdFZ4f+c2pErxV1q/6B99RbURKGNY1XdVz75pvyRr+FLK lfi7y31FWO0n8wJEScWtdesu8azRKAg+B/Eoi/5/+594eJgWnMtC4mzlK2l+QIsFDd4s DelP3avI2p+pyy/Bs3jOUVAFbBBgXGR2xoCm+2+zPa/DDL4KKkJvpIyd3Te/pc9g2c18 4n80ZExornOw3R8OOzoGLXAdB5W9njmQb+vLDF/OyO9yXrJ6EzpOPw34oRXz5Tbh8gGG Y3tn9madLDh1aRCYVBlUf3b3koTT9tBab1853m1SrDdO8vHXgNMZqAE31xKeIcmY2WNP etdw== MIME-Version: 1.0 X-Received: by 10.50.147.10 with SMTP id tg10mr8285781igb.36.1432839198952; Thu, 28 May 2015 11:53:18 -0700 (PDT) Sender: jakub.php@gmail.com Received: by 10.107.153.74 with HTTP; Thu, 28 May 2015 11:53:18 -0700 (PDT) Date: Thu, 28 May 2015 19:53:18 +0100 X-Google-Sender-Auth: C3xNVP4g_v-AIpvaYs8dcvg419s Message-ID: To: PHP internals list Content-Type: multipart/alternative; boundary=089e0122a2d07953bd051728df20 Subject: JSON unicode escape issue and new constants From: bukka@php.net (Jakub Zelenka) --089e0122a2d07953bd051728df20 Content-Type: text/plain; charset=UTF-8 Hi, There are two issues (reported bugs but not really bugs) in json_decode related to \u escape. First one is json_decode('{"\u0000": 1}'); reported in https://bugs.php.net/bug.php?id=68546 That code result in fatal error due to using malformed property (private props starting with \0). I don't think that anything parsed in json_decode should result in a fatal error. That's why I would like to introduce a new json error called JSON_ERROR_MANGLED_PROPERTY_NAME . Second one is json_decode('"\ud834"'); which relusts non UTF string from JSON decoder. This is conformant to the JSON RFC 7159 as noted in section 8.2: However, the ABNF in this specification allows member names and string values to contain bit sequences that cannot encode Unicode characters; for example, "\uDEAD" (a single unpaired UTF-16 surrogate). Instances of this have been observed, for example, when a library truncates a UTF-16 string without checking whether the truncation split a surrogate pair. The behavior of software that receives JSON texts containing such values is unpredictable; for example, implementations might return different values for the length of a string value or even suffer fatal runtime exceptions. As the behavior is unpredictable, the current default result seems reasonable because PHP strings are not internally unicode encode. However there might be cases when user want to make sure that he/she gets unicode string. In that case I would like to add an option called: JSON_VALID_ESCAPED_UNICODE which will emit error called JSON_ERROR_UTF16 when such escape appears. I implemented this in jsond long time ago and think that it would be useful for the json as well. Thoughts? I'm happy with changing constant names if someone come up with a better names. I would like to patch master sometimes next week if they are no objections. Cheers Jakub --089e0122a2d07953bd051728df20--