Repository navigation
fix: serialize integers beyond safe range as BigInt (#3384) - #3390
Closed
Akash Sarangi (Roxen-AS) wants to merge 1 commit into
Closed
Akash Sarangi (Roxen-AS) wants to merge 1 commit into
Akash Sarangi (Roxen-AS) wants to merge 1 commit into
Conversation
Integers outside JavaScript safe integer range ±(2**53 - 1) were
previously sent as standard Numbers, causing silent rounding and precision loss
for large integers such as 64-bit timestamps and Snowflake IDs.
Serialize integers outside this range as {"bi": str(value)}, allowing exact
round-trips as BigInt without precision loss.
Fixes microsoft#3384
Signed-off-by: Roxen-AS <akash.arjun12@gmail.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3384
Problem
When passing large integers (such as integers beyond JavaScript's safe integer range ±(2**53 - 1), 64-bit nanosecond timestamps, database IDs, or Snowflake IDs) to
page.evaluate(),_inner_serialize_valuepreviously serialized all integers as standard Numbers{"n": value}.When serialized to JSON and handled by the JavaScript runtime, values outside the safe integer range are silently rounded to the nearest IEEE 754 double float, causing silent precision loss and data corruption.
Solution
playwright/_impl/protocol/serializers.py, serialize integers strictly outside ±(2**53 - 1) (abs(value) > MAX_SAFE_INTEGER) as{"bi": str(value)}.{"n": value}, preserving standard JavaScript arithmetic behavior.{"bi": ...}(deserializing to a JavaScriptBigInton the page and serializing back as{"bi": ...}), allowing large integers to round-trip with exact precision.tests/async/python/test_page_evaluate.py.Verification
2**53 + 1,2**64,-2**63,2**70).pytest tests/async/python/test_page_evaluate.py -k test_serializers_large_integersacross Chromium, Firefox, and WebKit (3 passed).flake8 playwright/_impl/protocol/serializers.py tests/async/python/test_page_evaluate.py(0 warnings).python scripts/check_test_registry.py(0 issues).