Skip to content

Commit 191ea3e

Browse files
committed
Fix error if "op" is boolean true
Reverts the change in 2b56e5d which introduced a bug if "op" is boolean true. Amends test to prevent future regression.
1 parent 02df617 commit 191ea3e

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

Diff for: src/JsonPatch.php

+7-9
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ public static function import(array $data)
7070
throw new MissingFieldException('path', $operation);
7171
}
7272

73+
if (!is_string($operation->op)) {
74+
throw new InvalidFieldTypeException('op', 'string', $operation);
75+
}
76+
if (!is_string($operation->path)) {
77+
throw new InvalidFieldTypeException('path', 'string', $operation);
78+
}
79+
7380
$op = null;
7481
switch ($operation->op) {
7582
case Add::OP:
@@ -91,17 +98,8 @@ public static function import(array $data)
9198
$op = new Test();
9299
break;
93100
default:
94-
if (!is_string($operation->op)) {
95-
throw new InvalidFieldTypeException('op', 'string', $operation);
96-
}
97-
98101
throw new UnknownOperationException($operation);
99102
}
100-
101-
if (!is_string($operation->path)) {
102-
throw new InvalidFieldTypeException('path', 'string', $operation);
103-
}
104-
105103
$op->path = $operation->path;
106104
if ($op instanceof OpPathValue) {
107105
if (property_exists($operation, 'value')) {

Diff for: tests/src/JsonPatchTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function provideInvalidFieldType()
137137
{
138138
return [
139139
'"op" invalid type' => [
140-
(object)array('op' => array('foo' => 'bar'), 'path' => '/123', 'value' => 'test'),
140+
(object)array('op' => true, 'path' => '/123', 'value' => 'test'),
141141
'Invalid field type - "op" should be of type: string',
142142
'op',
143143
'string'

0 commit comments

Comments
 (0)