Skip to content

https-request: handle large integers more robustly - #262

Merged
dscho merged 1 commit into
mainfrom
fix-json-parsing
Nov 26, 2026
Merged

dscho merged 1 commit into
mainfrom
fix-json-parsing

Conversation

@dscho

@dscho dscho commented Nov 26, 2026

Copy link
Copy Markdown
Member

The regular expression I wrote is actually incorrect. It matches long runs of digits in the middle of a SHA-256 checksum, for example. This is not theoretical: this problem occurred when I tried to release Git for Windows v2.56.1 and delayed up the publication for more than two hours.

Even changing the regular expression to /(^|[:\s[,]+)(\d+)($|[\s,]]+)/ would still risk matching large numbers in the middle of a string value and resulting in mismatches.

None of this fragile regular expression matching is actually necessary anymore: the JSON.parse()'s reviver function receives a context parameter (whose source contains the original text for all values of a primitive type) since Node.JS 21:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#browser_compatibility

And since we're only ever running this code in Azure Functions that use Node.JS 22 or newer, we can totally use that context.source to parse large numbers into BigInts.

The regular expression I wrote is actually incorrect. It matches long
runs of digits in the middle of a SHA-256 checksum, for example. This is
not theoretical: this problem occurred when I tried to release Git for
Windows v2.56.1 and delayed up the publication for more than two hours.

Even changing the regular expression to /(^|[:\s[,]+)(\d+)($|[\s,\]]+)/
would _still_ risk matching large numbers in the middle of a string
value and resulting in mismatches.

None of this fragile regular expression matching is actually necessary
anymore: the `JSON.parse()`'s `reviver` function receives a `context`
parameter (whose `source` contains the original text for all values of a
primitive type) since Node.JS 21:

  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#browser_compatibility

And since we're only ever running this code in Azure Functions that use
Node.JS 22 or newer, we can totally use that `context.source` to parse
large numbers into BigInts.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho
dscho merged commit 60d8622 into main Nov 26, 2026
1 check passed
@dscho
dscho deleted the fix-json-parsing branch November 26, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant