You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MatchJSON finds 12345678901234567890 equal to 12345678901234567891 #931
This is another bug found by our automated process of writing hegel tests in hegel-zoo, filed as asked in #925 and, as before, reviewed by hand first.
Two JSON documents whose only difference is an integer above 2^53 match: 12345678901234567890 matches 12345678901234567891, and {"id": 9007199254740993} matches {"id": 9007199254740992}. One step below 2^53 the same pair is correctly a mismatch, and MatchYAML tells the two ids apart:
package main
import (
"fmt""github.com/onsi/gomega"
)
funcmain() {
ok, err:=gomega.MatchJSON(`12345678901234567891`).Match(`12345678901234567890`)
fmt.Println("MatchJSON(12345678901234567891) on 12345678901234567890:", ok, err)
ok, err=gomega.MatchJSON(`{"id": 9007199254740992}`).Match(`{"id": 9007199254740993}`)
fmt.Println(`MatchJSON({"id": 9007199254740992}) on {"id": 9007199254740993}:`, ok, err)
ok, err=gomega.MatchJSON(`{"id": 9007199254740991}`).Match(`{"id": 9007199254740992}`)
fmt.Println(`MatchJSON({"id": 9007199254740991}) on {"id": 9007199254740992}:`, ok, err)
ok, err=gomega.MatchYAML(`{"id": 9007199254740992}`).Match(`{"id": 9007199254740993}`)
fmt.Println(`MatchYAML({"id": 9007199254740992}) on {"id": 9007199254740993}:`, ok, err)
}
Output:
MatchJSON(12345678901234567891) on 12345678901234567890: true <nil>
MatchJSON({"id": 9007199254740992}) on {"id": 9007199254740993}: true <nil>
MatchJSON({"id": 9007199254740991}) on {"id": 9007199254740992}: false <nil>
MatchYAML({"id": 9007199254740992}) on {"id": 9007199254740993}: false <nil>
I expected the first two lines to be false, as the third is and as MatchYAML gives for the same documents. Every number here fits in a uint64 and is exactly what encoding/json emits for one, so a test asserting such an id with MatchJSON passes on a neighbouring wrong id.
Tested on v1.43.1, which is also the current master (47f0f87).
I've delegated fixing this to Claude and checked the code it generated. Thanks for reporting!
MatchJSON now compares integers beyond ±2^53 exactly, so neighbouring large integers (IDs and the like) no longer match. To avoid breaking existing suites, all other numbers are still compared as float64s as before, so 1 still matches 1.0 and over-precise decimals still match their float64 rounding. (8ef1aa7, 630fe12)
Activity
fix: MatchJSON only compares integers beyond 2^53 exactly
onsi commentedon Sep 24, 2026
I've delegated fixing this to Claude and checked the code it generated. Thanks for reporting!
MatchJSONnow compares integers beyond ±2^53 exactly, so neighbouring large integers (IDs and the like) no longer match. To avoid breaking existing suites, all other numbers are still compared as float64s as before, so1still matches1.0and over-precise decimals still match their float64 rounding. (8ef1aa7, 630fe12)This will be released in v1.44.0.