Lua (Scribunto):Test code:
```
print( mw.dumpObject( mw.text.jsonDecode( "\"true\"" ) ), type( mw.text.jsonDecode( "\"true\"" ) ) )
"true" string<?php
function test( $test ) {
print( mw.dumpObject( mw.text.jsonDecode( "true" ) ), type( mw.text. $res = jsonD_decode( "true" ) ) )$test );
true boolean $err = $res === null ? ' (' . json_last_error_msg() . ')' : '';
print( mw.dumpObject( mw.text. echo "$test => " . var_export( jsonD_decode( "trueOBVIOUSLYnot" )$test ), type( mw.text.jsonDecode( "trueOBVIOUSLYnot" ) ) )1 ) . "$err\n";
true boolean FAIL}
echo PHP_VERSION . "\n";
print( mw.dumpObject( mw.text.jsonDecode( "\"false\"" ) ), type( mw.text.jsonDecode( "\"false\"" ) ) )echo "\nPassing tests:\n";
"false" stringtest( '"true"' );
print( mw.dumpObject( mw.text.jsonDecode( "false" ) ), type( mw.text.jsonDecode( "false" ) ) )test( 'true' );
test( '"false boolean"' );
print( mw.dumpObject( mw.text.jsonDecode( "falseOBVIOUSLYnot" ) ), type( mw.text.jsonDecode( "test( 'falseOBVIOUSLYnot" ) ) )' );
false boolean FAILtest( '"null"' );
test( 'null' );
print( mw.dumpObject( mw.text.jsonDecode( "\"null\"" ) ), type( mw.text.jsonDecode( "\"null\"" ) ) )echo "\nShould fail:\n";
"null" stringtest( 'trueOBVIOUSLYnot' );
print( mw.dumpObject( mw.text.jsonDecode( "null" ) ), type( mw.text.jsonDecode( "null" ) ) )test( 'falseOBVIOUSLYnot' );
nil niltest( 'nullOBVIOUSLYnot' );
print( mw.dumpObject( mw.text.jsonDecode( "nullOBVIOUSLYnot" ) )test( 'true, type( mw.text.jsonDecode( "nullOBVIOUSLYnot" ) ) ){} nil; [] false' );
nil nil FAIL```
-- Even much obscure things fail:
print( mw.dumpObject( mw.text.jsonDecode( "true, {} nil; [] false" ) ), type( mw.text.jsonDecode( "true, {} nil; [] false" ) ) )
true booleanResult in HHVM 3.6.5+dfsg1-1+wm1:
```
PHP:$ php test-107132.php
5.6.99-hhvm
Passing tests:
```"true" => 'true'
var_dump( json_decode( "\"true => true\"" ) );
string(4) "true""false" => 'false'
var_dump( json_decode( "true" ) );false => false
bool(true)"null" => 'null'
var_dump( json_decode( "trueOBVIOUSLYnot" ) );null => NULL (No error)
Should fail:
NULLtrueOBVIOUSLYnot => true
var_dump( json_last_error() );falseOBVIOUSLYnot => false
int(4) // JSON_ERROR_SYNTAX
var_dump( json_decode( "\"false\"" ) );nullOBVIOUSLYnot => NULL (No error)
string(5) "true, {} nil; [] false" => true
var_dump( json_decode( "false" ) );```
Result in 5.5.9+dfsg-1ubuntu4.11:
bool(false)```
var_dump( json_decode( "falseOBVIOUSLYnot" ) );5.5.9-1ubuntu4.11
Passing tests:
NULL"true" => 'true'
var_dump( json_last_error() );true => true
int(4) // JSON_ERROR_SYNTAX
var_dump( json_decode( "\"null\"" ) );"false" => 'false'
string(4) "null"false => false
var_dump( json_decode( ""null" => 'null" ) );'
null => NULL (No error)
Should fail:
var_dump( json_decode( "nullOBVIOUSLYnot" ) );trueOBVIOUSLYnot => NULL (unexpected character)
NULL // NULL is returned if the json cannot be decoded or if the encoded data is deeper than the recursion limit.falseOBVIOUSLYnot => NULL (unexpected character)
var_dump( json_last_error() );nullOBVIOUSLYnot => NULL (unexpected character)
int(4) // JSON_ERROR_SYNTAXtrue, {} nil; [] false => NULL (unexpected character)
```
Tim reports this is fixed in the newest upstream versions, although the linked diff seems too old. It looks like it actually depends on whether HHVM is compiled to use json-c over its internal "no evil"-licensed version.
According to the documentation for json-c's json_tokener_parse_ex(), HHVM should be performing an additional check that it isn't performing. Upstream bug report is https://github.com/facebook/hhvm/issues/5812.