Skip to content

Commit a002ca6

Browse files
committed
Compare strings after decoding them to handle unicode correctly
1 parent f72a464 commit a002ca6

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

v5/patch.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,27 @@ func (n *lazyNode) equal(o *lazyNode) bool {
334334
return false
335335
}
336336

337-
return bytes.Equal(n.compact(), o.compact())
337+
nc := n.compact()
338+
oc := o.compact()
339+
340+
if nc[0] == '"' && oc[0] == '"' {
341+
// ok, 2 strings
342+
343+
var ns, os string
344+
345+
err := json.Unmarshal(nc, &ns)
346+
if err != nil {
347+
return false
348+
}
349+
err = json.Unmarshal(oc, &os)
350+
if err != nil {
351+
return false
352+
}
353+
354+
return ns == os
355+
}
356+
357+
return bytes.Equal(nc, oc)
338358
}
339359
}
340360

v5/patch_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,12 @@ var EqualityCases = []EqualityCase{
10781078
`null`,
10791079
false,
10801080
},
1081+
{
1082+
"Unicode",
1083+
`{"name": "λJohn"}`,
1084+
`{"name": "\u03BBJohn"}`,
1085+
true,
1086+
},
10811087
}
10821088

10831089
func TestEquality(t *testing.T) {

0 commit comments

Comments
 (0)