Skip to content

MatchJSON finds 12345678901234567890 equal to 12345678901234567891 #931

Closed

Description

@DRMacIver

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"
)

func main() {
	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).

Activity

  1. onsi commented on Sep 24, 2026

    @onsi
    Owner

    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)

    This will be released in v1.44.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions