File tree Expand file tree Collapse file tree 4 files changed +56
-0
lines changed Expand file tree Collapse file tree 4 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
4
4
The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
5
5
and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) .
6
6
7
+ ## [ 3.7.3] - 2020-01-24
8
+
9
+ ### Fixed
10
+ - Merge patch was not replacing partially different arrays.
11
+
7
12
## [ 3.7.2] - 2019-10-23
8
13
9
14
### Added
@@ -30,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
30
35
### Added
31
36
- Compatibility option to ` TOLERATE_ASSOCIATIVE_ARRAYS ` that mimic JSON objects.
32
37
38
+ [ 3.7.3 ] : https://github.com/swaggest/json-diff/compare/v3.7.2...v3.7.3
33
39
[ 3.7.2 ] : https://github.com/swaggest/json-diff/compare/v3.7.1...v3.7.2
34
40
[ 3.7.1 ] : https://github.com/swaggest/json-diff/compare/v3.7.0...v3.7.1
35
41
[ 3.7.0 ] : https://github.com/swaggest/json-diff/compare/v3.6.0...v3.7.0
Original file line number Diff line number Diff line change @@ -323,6 +323,7 @@ private function process($original, $new)
323
323
}
324
324
325
325
$ isUriFragment = (bool )($ this ->options & self ::JSON_URI_FRAGMENT_ID );
326
+ $ diffCnt = $ this ->addedCnt + $ this ->modifiedCnt + $ this ->removedCnt ;
326
327
foreach ($ originalKeys as $ key => $ originalValue ) {
327
328
if ($ this ->options & self ::STOP_ON_DIFF ) {
328
329
if ($ this ->modifiedCnt || $ this ->addedCnt || $ this ->removedCnt ) {
@@ -366,6 +367,10 @@ private function process($original, $new)
366
367
$ this ->pathItems = $ pathItems ;
367
368
}
368
369
370
+ if ($ merge && $ isArray && $ this ->addedCnt + $ this ->modifiedCnt + $ this ->removedCnt > $ diffCnt ) {
371
+ JsonPointer::add ($ this ->merge , $ this ->pathItems , $ new );
372
+ }
373
+
369
374
// additions
370
375
foreach ($ newArray as $ key => $ value ) {
371
376
$ this ->addedCnt ++;
Original file line number Diff line number Diff line change
1
+ {
2
+ "key1" : [
3
+ 5 ,
4
+ 1 ,
5
+ 2 ,
6
+ 3
7
+ ],
8
+ "key2" : null ,
9
+ "key3" : {
10
+ "sub0" : null ,
11
+ "sub1" : " c" ,
12
+ "sub2" : false ,
13
+ "sub3" : 0
14
+ },
15
+ "key4" : [
16
+ {
17
+ "c" : false ,
18
+ "a" : 2
19
+ },
20
+ {
21
+ "a" : 1 ,
22
+ "b" : true
23
+ },
24
+ {
25
+ "c" : 1 ,
26
+ "a" : 3
27
+ }
28
+ ],
29
+ "key5" : " wat"
30
+ }
Original file line number Diff line number Diff line change @@ -289,5 +289,20 @@ protected function doTest($case)
289
289
290
290
}
291
291
292
+ public function testComplex ()
293
+ {
294
+ $ original = json_decode (file_get_contents (__DIR__ . '/../assets/original.json ' ));
295
+ $ new = json_decode (file_get_contents (__DIR__ . '/../assets/new.json ' ));
296
+
297
+ $ diff = new JsonDiff ($ original , $ new );
298
+ $ mergePatch = $ diff ->getMergePatch ();
299
+ $ mergePatchJson = json_encode ($ mergePatch , JSON_UNESCAPED_SLASHES + JSON_PRETTY_PRINT );
300
+
301
+ $ this ->assertEquals (file_get_contents (__DIR__ . '/../assets/merge.json ' ) , $ mergePatchJson );
302
+
303
+ JsonMergePatch::apply ($ original , $ mergePatch );
304
+ $ this ->assertEquals ($ new , $ original );
305
+ }
306
+
292
307
293
308
}
You can’t perform that action at this time.
0 commit comments