#41034 [Opn->Asn]: json_encode ignores null byte started keys in arrays

From: Date: Tue, 10 Apr 2007 10:00:51 +0000
Subject: #41034 [Opn->Asn]: json_encode ignores null byte started keys in arrays
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-111281@lists.php.net to get a copy of this message
ID: 41034 Updated by: tony2001@php.net Reported By: php at sameprecision dot org -Status: Open +Status: Assigned Bug Type: Unknown/Other Function Operating System: suse linux 10, windows XP sp2 PHP Version: 5.2.1 -Assigned To: +Assigned To: tony2001 Previous Comments: ------------------------------------------------------------------------ [2007-04-10 04:40:29] php at sameprecision dot org Description: ------------ If a key in an array starts with the null byte, json_encode ignores that key=>value pair. This seems wrong because json_encode doesn't care about null bytes anywhere in the value (and neither does javascript, about keys or values). Reproduce code: --------------- //works as expected: echo json_encode(array(0,"a\0b"=>1,"\0null-prefixed value")); echo "\n\n"; //ignores second element whose key begins with null byte: echo json_encode(array(0,"\0ab"=>1,"\0null-prefixed value")); Expected result: ---------------- {"0":0,"a\0b":1,"1":"\0null-prefixed value"} {"0":0,"\0ab":1,"1":"\0null-prefixed value"} // \0 represents an actual null byte here Actual result: -------------- {"0":0,"a\0b":1,"1":"\0null-prefixed value"} {"0":0,"1":"\0null-prefixed value"} // \0 represents an actual null byte here ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=41034&edit=1

« previous php.bugs (#111281) next »