From bfd42e8a2fbdc5cf0b6cfe888298480fdfc852a7 Mon Sep 17 00:00:00 2001 From: Guillaume de Sagazan Date: Thu, 8 Nov 2018 11:19:30 +0100 Subject: [PATCH] --ignore failed to match json-paths containing arrays Adding indices in json-paths prevented the glob library from matching `.foo\[\]` to any index in the array. --- Readme.md | 10 +++++----- patterns.go | 2 ++ test_files/rhs.json | 2 +- tests.sh | 13 +++++++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Readme.md b/Readme.md index 120f4d7..e22b3e4 100644 --- a/Readme.md +++ b/Readme.md @@ -94,9 +94,9 @@ Report format: ```diff $ jaydiff --report --show-types old.json new.json -- .b[]: float64 3 -+ .b[]: float64 5 -+ .b[]: float64 4 +- .b[1]: float64 3 ++ .b[1]: float64 5 ++ .b[2]: float64 4 - .c.a: string toto + .c.a: string titi - .c.b: float64 23 @@ -137,8 +137,8 @@ Ignore Excess values (useful when checking for backward compatibility): ```diff $ jaydiff --report --show-types --ignore-excess old.json new.json -- .b[]: float64 3 -+ .b[]: float64 5 +- .b[1]: float64 3 ++ .b[1]: float64 5 - .c.a: string toto + .c.a: string titi - .c.b: float64 23 diff --git a/patterns.go b/patterns.go index a894c02..4715aa3 100644 --- a/patterns.go +++ b/patterns.go @@ -2,6 +2,7 @@ package main import ( "github.com/gobwas/glob" + "github.com/yazgazan/jaydiff/jpath" ) type ignorePattern struct { @@ -25,6 +26,7 @@ func (p *ignorePatterns) UnmarshalFlag(s string) error { } func (p ignorePatterns) Match(s string) bool { + s = jpath.StripIndices(s) for _, pattern := range p { if pattern.Match(s) { return true diff --git a/test_files/rhs.json b/test_files/rhs.json index 125da51..8dff7e5 100644 --- a/test_files/rhs.json +++ b/test_files/rhs.json @@ -3,7 +3,7 @@ "b": [ 1, 5, - 4 + 4 ], "c": { "a": "titi", diff --git a/tests.sh b/tests.sh index 9568d05..53e7e85 100755 --- a/tests.sh +++ b/tests.sh @@ -26,6 +26,19 @@ else fi echo +echo "./jaydiff --show-types --ignore(all):" +./jaydiff --indent=' ' --show-types \ + --ignore='.b\[\]' --ignore='.[c-h]' \ + test_files/lhs.json test_files/rhs.json +CODE=$? +if [[ $CODE -ne 0 ]]; then + echo "FAIL with code $CODE" + FAILED=1 +else + echo "OK" +fi +echo + echo "./jaydiff --report --show-types:" ./jaydiff --report --indent=' ' --show-types \ test_files/lhs.json test_files/rhs.json