Skip to content

Commit bfd42e8

Browse files
committed
--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.
1 parent 3846f53 commit bfd42e8

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

Readme.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ Report format:
9494
```diff
9595
$ jaydiff --report --show-types old.json new.json
9696

97-
- .b[]: float64 3
98-
+ .b[]: float64 5
99-
+ .b[]: float64 4
97+
- .b[1]: float64 3
98+
+ .b[1]: float64 5
99+
+ .b[2]: float64 4
100100
- .c.a: string toto
101101
+ .c.a: string titi
102102
- .c.b: float64 23
@@ -137,8 +137,8 @@ Ignore Excess values (useful when checking for backward compatibility):
137137
```diff
138138
$ jaydiff --report --show-types --ignore-excess old.json new.json
139139

140-
- .b[]: float64 3
141-
+ .b[]: float64 5
140+
- .b[1]: float64 3
141+
+ .b[1]: float64 5
142142
- .c.a: string toto
143143
+ .c.a: string titi
144144
- .c.b: float64 23

patterns.go

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"github.com/gobwas/glob"
5+
"github.com/yazgazan/jaydiff/jpath"
56
)
67

78
type ignorePattern struct {
@@ -25,6 +26,7 @@ func (p *ignorePatterns) UnmarshalFlag(s string) error {
2526
}
2627

2728
func (p ignorePatterns) Match(s string) bool {
29+
s = jpath.StripIndices(s)
2830
for _, pattern := range p {
2931
if pattern.Match(s) {
3032
return true

test_files/rhs.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"b": [
44
1,
55
5,
6-
4
6+
4
77
],
88
"c": {
99
"a": "titi",

tests.sh

+13
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ else
2626
fi
2727
echo
2828

29+
echo "./jaydiff --show-types --ignore(all):"
30+
./jaydiff --indent=' ' --show-types \
31+
--ignore='.b\[\]' --ignore='.[c-h]' \
32+
test_files/lhs.json test_files/rhs.json
33+
CODE=$?
34+
if [[ $CODE -ne 0 ]]; then
35+
echo "FAIL with code $CODE"
36+
FAILED=1
37+
else
38+
echo "OK"
39+
fi
40+
echo
41+
2942
echo "./jaydiff --report --show-types:"
3043
./jaydiff --report --indent=' ' --show-types \
3144
test_files/lhs.json test_files/rhs.json

0 commit comments

Comments
 (0)