Repository navigation
fix: validateJSON large-text rejection serialized the input and left its errors unordered - #112
Merged
Merged
Conversation
…es as valid and errors, not the input text
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 11 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
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.
With
richErrors: false, the native engine loaded and a document of 8 KB or more,validateJSON()returns a rejection decided from the text alone (TextRejection in lib/codegen-engine.js). Its errors are built on first read. Two things were wrong with it:JSON.stringify(result)wrote its private fields, the whole input text among them, and no errors. A server that answers withres.json(result)echoed the client's document back without saying what was wrong. On a 9 KB document the old code serialized 9067 characters of input; it now serializes{ valid, errors }as the other rejections do.validate()gives them. The layer that orders validateJSON's errors with richErrors off only acts on a document parsed during the call. The rejection now orders its own list on first read. A caller reading only.validstill parses nothing (test_lazy_json_errors).The verdict and the set of errors were already right. With richErrors on, both were already handled by the rich layer.
Found by a sweep of every Validator entry point (generated code cold and warm, closure tree, validateJSON) against the interpreted engine under nine option sets (coerceTypes, removeAdditional, both, useDefaults false, assertFormat false, abortEarly, richErrors false, coerceTypes with richErrors false, removeAdditional with useDefaults false), on the official suite in six dialects and SchemaStore with documents changed to strings and given extra keys. The order was the only difference: two SchemaStore schemas, aspire-8.0 and popxf-corr-1.0. After the fix, all 36 rows are at 0. A control path that drops the options shows 91 to 7584 differences per row, so the sweep sees them.
The fix is in lib/codegen-engine.js only. A first version in lib/validator-core.js added 13 bytes to ata-validator/lite, which has no code generator; this one leaves lite at 62008. The tarball ceiling in test_pack_purity moves from 662 to 663 KB with the reason written next to it (measured 662.1 KB, mostly CHANGELOG entries of the fixes since the last ceiling).
tests/test_json_plain_error_order.js checks order and serialization at 0, 9000 and 20000 bytes of padding, plus the syntax-error and abortEarly shapes. It fails on the old code and passes with and without the native engine.
Verified: npm test (366 files after merging master), npm run test:suite (every dialect in full, 0 regressions), test_no_eval, release:check, SchemaStore gate (17 paths, 0 differ).
Not covered: the sweep harness stays outside the repo. Option sets beyond the nine above were not swept.