Skip to content

Commit

Permalink
Explicit intish cast in json_decode
Browse files Browse the repository at this point in the history
Summary: What it says on the tin

Reviewed By: huntergoldstein

Differential Revision: D13053395

fbshipit-source-id: 58c7acc447f911981af41d0e3654b260517ba420
  • Loading branch information
Joseph Griego authored and hhvm-bot committed Nov 15, 2018
1 parent f84da1f commit dc265de
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 4 deletions.
14 changes: 12 additions & 2 deletions hphp/runtime/ext/json/JSON_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,9 +901,19 @@ static void object_set(Variant &var,
forceToDict(var).set(key, value);
} else if (container_type == JSONContainerType::DARRAYS ||
container_type == JSONContainerType::DARRAYS_AND_VARRAYS) {
forceToDArray(var).set(key, value);
int64_t i;
if (key.get()->isStrictlyInteger(i)) {
forceToDArray(var).set(i, value);
} else {
forceToDArray(var).set(key, value);
}
} else {
forceToArray(var).set(key, value);
int64_t i;
if (key.get()->isStrictlyInteger(i)) {
forceToArray(var).set(i, value);
} else {
forceToArray(var).set(key, value);
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions hphp/runtime/ext/json/ext_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ TypedValue HHVM_FUNCTION(json_encode, const Variant& value,

TypedValue HHVM_FUNCTION(json_decode, const String& json,
bool assoc, int64_t depth, int64_t options) {
SuppressHACIntishCastNotices shacn;

json_set_last_error_code(json_error_codes::JSON_ERROR_NONE);

if (json.empty()) {
Expand Down
6 changes: 6 additions & 0 deletions hphp/test/slow/dv_array/json-decode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?hh

<<__EntryPoint>>
function main() {
var_dump(json_decode("{\"1\": 1, \"2\": \"2\"}", true, 512, JSON_FB_DARRAYS));
}
6 changes: 6 additions & 0 deletions hphp/test/slow/dv_array/json-decode.php.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
array(2) {
[1]=>
int(1)
[2]=>
string(1) "2"
}
2 changes: 2 additions & 0 deletions hphp/test/slow/dv_array/json-decode.php.hphp_opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-vRuntime.Eval.HackArrCompatNotices=1
-vRuntime.Eval.HackArrCompatCheckIntishCast=1
2 changes: 2 additions & 0 deletions hphp/test/slow/dv_array/json-decode.php.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-vEval.HackArrCompatNotices=1
-vEval.HackArrCompatCheckIntishCast=1
6 changes: 6 additions & 0 deletions hphp/test/slow/dv_array_hack_arr/json-decode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?hh

<<__EntryPoint>>
function main() {
var_dump(json_decode("{\"1\": 1, \"2\": \"2\"}", true, 512, JSON_FB_DARRAYS));
}
6 changes: 6 additions & 0 deletions hphp/test/slow/dv_array_hack_arr/json-decode.php.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dict(2) {
[1]=>
int(1)
[2]=>
string(1) "2"
}
3 changes: 3 additions & 0 deletions hphp/test/slow/dv_array_hack_arr/json-decode.php.hphp_opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-vRuntime.Eval.HackArrCompatNotices=1
-vRuntime.Eval.HackArrCompatCheckIntishCast=1
-vRuntime.Eval.HackArrDVArrs=1
3 changes: 3 additions & 0 deletions hphp/test/slow/dv_array_hack_arr/json-decode.php.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-vEval.HackArrCompatNotices=1
-vEval.HackArrCompatCheckIntishCast=1
-vEval.HackArrDVArrs=1

0 comments on commit dc265de

Please sign in to comment.