-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from BitOne/GIT-49_pipe_char_in_json
Fixes #49 by escaping control chars
- Loading branch information
Showing
9 changed files
with
239 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
extension/php5/tests/bug-git-49_escape_control_character.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--TEST-- | ||
Check that control character in array key are properly escaped for json | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded('json')) die('skip json ext not loaded'); | ||
?> | ||
--FILE-- | ||
<?php | ||
$myArray = [ | ||
"1|\x1f" => "My data" | ||
]; | ||
|
||
$dump = fopen('php://memory', 'rw'); | ||
|
||
meminfo_dump($dump); | ||
|
||
rewind($dump); | ||
$meminfoData = json_decode(stream_get_contents($dump), true); | ||
fclose($dump); | ||
|
||
if (is_array($meminfoData)) { | ||
echo "meminfo_dump JSON decode ok\n"; | ||
} else { | ||
echo "meminfo_dump JSON decode fail\n"; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
meminfo_dump JSON decode ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--TEST-- | ||
Check JSON proper escaping (see http://json.org) | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded('json')) die('skip json ext not loaded'); | ||
?> | ||
--FILE-- | ||
<?php | ||
$jsonCharactersToEscape = [ | ||
'"' => 'quotation mark', | ||
'\\' => "reverse solidus", | ||
'/' => "solidus" | ||
]; | ||
|
||
for ($i = 0; $i <= 0x1f; $i++) { | ||
$jsonCharactersToEscape[chr($i)] = "control character $i"; | ||
} | ||
|
||
$dump = fopen('php://memory', 'rw'); | ||
|
||
meminfo_dump($dump); | ||
|
||
rewind($dump); | ||
$meminfoData = json_decode(stream_get_contents($dump), true); | ||
fclose($dump); | ||
|
||
if (is_array($meminfoData)) { | ||
echo "meminfo_dump JSON decode ok\n"; | ||
} else { | ||
echo "meminfo_dump JSON decode fail\n"; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
meminfo_dump JSON decode ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--TEST-- | ||
Check JSON proper escaping (see http://json.org) | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded('json')) die('skip json ext not loaded'); | ||
?> | ||
--FILE-- | ||
<?php | ||
$myArrayWithUnicodeKey = [ | ||
'✈' => 'plane character' | ||
]; | ||
|
||
$dump = fopen('php://memory', 'rw'); | ||
|
||
meminfo_dump($dump); | ||
|
||
rewind($dump); | ||
$meminfoData = json_decode(stream_get_contents($dump), true); | ||
fclose($dump); | ||
|
||
if (is_array($meminfoData)) { | ||
echo "meminfo_dump JSON decode ok\n"; | ||
} else { | ||
echo "meminfo_dump JSON decode fail\n"; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
meminfo_dump JSON decode ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
extension/php7/tests/bug-git-49_escape_control_character.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--TEST-- | ||
Check that control character in array key are properly escaped for json | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded('json')) die('skip json ext not loaded'); | ||
?> | ||
--FILE-- | ||
<?php | ||
$myArray = [ | ||
"1|\x1f" => "My data" | ||
]; | ||
|
||
$dump = fopen('php://memory', 'rw'); | ||
|
||
meminfo_dump($dump); | ||
|
||
rewind($dump); | ||
$meminfoData = json_decode(stream_get_contents($dump), true); | ||
fclose($dump); | ||
|
||
if (is_array($meminfoData)) { | ||
echo "meminfo_dump JSON decode ok\n"; | ||
} else { | ||
echo "meminfo_dump JSON decode fail\n"; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
meminfo_dump JSON decode ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--TEST-- | ||
Check JSON proper escaping (see http://json.org) | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded('json')) die('skip json ext not loaded'); | ||
?> | ||
--FILE-- | ||
<?php | ||
$jsonCharactersToEscape = [ | ||
'"' => 'quotation mark', | ||
'\\' => "reverse solidus", | ||
'/' => "solidus" | ||
]; | ||
|
||
for ($i = 0; $i <= 0x1f; $i++) { | ||
$jsonCharactersToEscape[chr($i)] = "control character $i"; | ||
} | ||
|
||
$dump = fopen('php://memory', 'rw'); | ||
|
||
meminfo_dump($dump); | ||
|
||
rewind($dump); | ||
$meminfoData = json_decode(stream_get_contents($dump), true); | ||
fclose($dump); | ||
|
||
if (is_array($meminfoData)) { | ||
echo "meminfo_dump JSON decode ok\n"; | ||
} else { | ||
echo "meminfo_dump JSON decode fail\n"; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
meminfo_dump JSON decode ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--TEST-- | ||
Check JSON proper escaping (see http://json.org) | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded('json')) die('skip json ext not loaded'); | ||
?> | ||
--FILE-- | ||
<?php | ||
$myArrayWithUnicodeKey = [ | ||
'✈' => 'plane character' | ||
]; | ||
|
||
$dump = fopen('php://memory', 'rw'); | ||
|
||
meminfo_dump($dump); | ||
|
||
rewind($dump); | ||
$meminfoData = json_decode(stream_get_contents($dump), true); | ||
fclose($dump); | ||
|
||
if (is_array($meminfoData)) { | ||
echo "meminfo_dump JSON decode ok\n"; | ||
} else { | ||
echo "meminfo_dump JSON decode fail\n"; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
meminfo_dump JSON decode ok |