Skip to content

Commit 7c10c55

Browse files
authored
test(reconcile): guard canonicalJSON number precision with a 2^53 pair (#1884)
1 parent 5bacc1b commit 7c10c55

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎internal/reconcile/metaschema_test.go‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,13 @@ func TestCanonicalJSON(t *testing.T) {
129129
assert.Error(t, err)
130130
})
131131
t.Run("keeps a real difference in a large integer", func(t *testing.T) {
132-
a, err := canonicalJSON(`{"maximum":10000000000000001}`)
132+
// 2^53+1 and 2^53 both round to 2^53 under a float64 decode, so this pair
133+
// fails without the UseNumber decode and passes with it. A larger pair like
134+
// 1e16+1 vs 1e16+2 would round to distinct floats and pass either way, so it
135+
// would not guard the fix.
136+
a, err := canonicalJSON(`{"maximum":9007199254740993}`)
133137
assert.NoError(t, err)
134-
b, err := canonicalJSON(`{"maximum":10000000000000002}`)
138+
b, err := canonicalJSON(`{"maximum":9007199254740992}`)
135139
assert.NoError(t, err)
136140
assert.NotEqual(t, a, b)
137141
})

0 commit comments

Comments
 (0)