Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59341 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67100 invoked from network); 3 Apr 2012 07:50:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Apr 2012 07:50:46 -0000 Authentication-Results: pb1.pair.com smtp.mail=laruence@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=laruence@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.170 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.220.170 mail-vx0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:61009] helo=mail-vx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BC/02-54877-6DBAA7F4 for ; Tue, 03 Apr 2012 03:50:46 -0400 Received: by vcbfo14 with SMTP id fo14so2535769vcb.29 for ; Tue, 03 Apr 2012 00:50:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=FIkdTHvFJh/BFw3MRCfuTASw9N1YA85NhZkpD/uVhT8=; b=RuP7o7vPdbMoavSDPixz9qYSGy4qB4rk6R6ree5vL7QsS4+K9Wm/YmzvM5DxIsJiSH VXFeu46W8nhCYPWYeSASQa4CGToGqFaPAAICtG0pJeX2ThuAWfP/9pgD+5WP/zJtgEtd EEEcWAhjlVvd7dURp0w680txEQInBNwIoA5W9X4fzsJI/39m2Qqr8Ek4H1ALluORTHnp ocAJfNUPiwECAz93sCIPtNwwX9Ld9rSVlzPnrPwlSmijEn/uWV/CL9hKacxgbGZK0d+9 wHEl1FF4wvBE63YBi8i1J4Z42zo2qRu7GtHJQHJoxaB0UHY6m+yzxXvlXeQeYyjNMKQS z8Kw== Received: by 10.52.15.233 with SMTP id a9mr5124710vdd.34.1333439443719; Tue, 03 Apr 2012 00:50:43 -0700 (PDT) MIME-Version: 1.0 Sender: laruence@gmail.com Received: by 10.220.18.194 with HTTP; Tue, 3 Apr 2012 00:50:23 -0700 (PDT) In-Reply-To: <4F7A5684.4050102@lerdorf.com> References: <7EBB3287C8464A93B2B264FDAD2B6756@charliesomerville.com> <4F7A5684.4050102@lerdorf.com> Date: Tue, 3 Apr 2012 15:50:23 +0800 X-Google-Sender-Auth: q5KlNE-3xLiqGoz6MLiovd2RMtE Message-ID: To: Rasmus Lerdorf Cc: Charlie Somerville , internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] json_encode() and non-UTF8 strings From: laruence@php.net (Laruence) On Tue, Apr 3, 2012 at 9:46 AM, Rasmus Lerdorf wrote: > On 04/02/2012 06:35 PM, Charlie Somerville wrote: >> Hi internals, >> >> I've created a pull request (https://github.com/php/php-src/pull/33) tha= t changes json_encode to fall back to ASCII for strings that are not valid = UTF-8. >> >> I ran into an issue in a production application involving PayPal IPN cal= lbacks (which are sent encoded as windows-1252) and json_encode(). If there= was an accented character present in the data, json_encode() would fail to= encode the string and serialize it as 'null'. >> >> I've modified the behaviour of the underlying json_escape_string() imple= mentation to attempt to encode strings anyway while still producing a warni= ng. > > JSON with non-Unicode strings is no longer JSON. The spec is explicit > that all strings must be Unicode. The default encoding is UTF-8, but it > could be UTF-16/32 as well. agree, allowing json code in no-utf8 charset is a wrong way. especially in json-rpc, it will make things mess.. thanks > > See http://www.ietf.org/rfc/rfc4627.txt > > -Rasmus > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > --=20 Laruence =C2=A0Xinchen Hui http://www.laruence.com/