From c8610a9b77be762fdfc00c37820291be36026e9c Mon Sep 17 00:00:00 2001 From: Marcin Warpechowski Date: Tue, 19 Mar 2013 10:45:49 +0100 Subject: [PATCH 1/4] add PHPStorm to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index da4e509..a6b6702 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ \#* +.idea From 472e5af6cc5aecc5f67a1970687536655e45815b Mon Sep 17 00:00:00 2001 From: Marcin Warpechowski Date: Tue, 19 Mar 2013 10:47:43 +0100 Subject: [PATCH 2/4] use standard PHP tags --- JsonPatch.inc | 2 +- run_tests.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/JsonPatch.inc b/JsonPatch.inc index 49bb63e..6dc3551 100644 --- a/JsonPatch.inc +++ b/JsonPatch.inc @@ -1,4 +1,4 @@ - Date: Tue, 19 Mar 2013 11:46:31 +0100 Subject: [PATCH 3/4] apply changes according to Draft 10, update tests from upstream --- JsonPatch.inc | 59 +++++++++++++++++------------------------------- json-patch-tests | 2 +- 2 files changed, 22 insertions(+), 39 deletions(-) diff --git a/JsonPatch.inc b/JsonPatch.inc index 6dc3551..216ed92 100644 --- a/JsonPatch.inc +++ b/JsonPatch.inc @@ -89,24 +89,19 @@ class JsonPatch foreach ($patches as $patch) { - $found = false; - foreach (array('add', 'remove', 'replace', 'move', 'copy', 'test') - as $op) - { - if (isset($patch[$op])) { - $location = $patch[$op]; - $found = true; - break; - } + $op = trim($patch['op']); //one test in tests.json defines "op":" add" + + if (empty($op)) { + throw new JsonPatchException("Operation member 'op' missing in " + . json_encode($patch)); } - if (!$found) - { + if (!in_array($op, array('add', 'remove', 'replace', 'move', 'copy', 'test'))) { throw new JsonPatchException("Unrecognized operation $op in " - . json_encode($patch)); + . json_encode($patch)); } - $parts = self::decompose_pointer($location); + $parts = self::decompose_pointer($patch['path']); if (in_array($op, Array('test', 'add', 'replace'))) { $value = $patch['value']; @@ -392,7 +387,7 @@ class JsonPatch { throw new JsonPatchException("'test' target value different - expected " . json_encode($value) . ", found " - . json_encode($found));; + . json_encode($found)); } } @@ -510,18 +505,11 @@ class JsonPatch throw new JsonPatchException('Target must be array or associative array'); } - if (self::is_associative($doc)) // N.B. returns false for empty arrays - { - if (is_numeric($part)) - { - throw new JsonPatchException('Array operation on object target'); - } - } - else + if (!self::is_associative($doc)) // N.B. returns false for empty arrays { if (count($doc) && !is_numeric($part)) { - throw new JsonPatchException('Non-array operation on array target'); + throw new JsonPatchException('Non-array operation on array target'); } else { @@ -537,13 +525,13 @@ class JsonPatch if ($op == 'add') { - if (is_numeric($part)) + if (!self::is_associative($doc) && is_numeric($part)) { array_splice($doc, $part, 0, Array($value)); } else { - if (array_key_exists($part, $doc)) + if (array_key_exists($part, $doc) && !is_null($doc[$part])) { throw new JsonPatchException("'add' target '$part' already set"); } @@ -600,24 +588,19 @@ class JsonPatch foreach ($patches as $patch) { - $found = false; - foreach (array('add', 'remove', 'replace', 'move', 'copy', 'test') - as $op) - { - if (isset($patch[$op])) { - $location = $patch[$op]; - $found = true; - break; - } + $op = trim($patch['op']); //one test in tests.json defines "op":" add" + + if (empty($op)) { + throw new JsonPatchException("Operation member 'op' missing in " + . json_encode($patch)); } - if (!$found) - { + if (!in_array($op, array('add', 'remove', 'replace', 'move', 'copy', 'test'))) { throw new JsonPatchException("Unrecognized operation $op in " - . json_encode($patch)); + . json_encode($patch)); } - $parts = self::decompose_pointer($location); + $parts = self::decompose_pointer($patch['path']); if (in_array($op, Array('test', 'add', 'replace'))) { $value = $patch['value']; diff --git a/json-patch-tests b/json-patch-tests index 87ed9e0..5b6bc0d 160000 --- a/json-patch-tests +++ b/json-patch-tests @@ -1 +1 @@ -Subproject commit 87ed9e04032508dd06c0678b0a0f89e72daa3b7f +Subproject commit 5b6bc0dfae8fa45f648eaf3ae9b3cd199a6dc067 From df80c25a152e063e7a9c158be2b086b2a6464b2a Mon Sep 17 00:00:00 2001 From: Marcin Warpechowski Date: Tue, 19 Mar 2013 11:51:43 +0100 Subject: [PATCH 4/4] update draft links --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 830d10e..d7e0d74 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ Produce and apply json-patch objects. Implements the IETF json-patch and json-pointer drafts: -http://tools.ietf.org/html/draft-ietf-appsawg-json-patch-02 +http://tools.ietf.org/html/draft-ietf-appsawg-json-patch-10 -http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-02 +http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-09 Entry points ------------