fix(#782): tolerate trailing bytes when reading eo-foreign.json#944
Merged
Conversation
…n.json The `foreign` command failed on Windows CI with `Unexpected non-whitespace character after JSON at position N (line N column 2)` when something appended content after the first balanced JSON array in `eo-foreign.json`. Parse only the first balanced `[...]` array (strip UTF-8 BOM, respect string literals) instead of feeding the raw file to `JSON.parse`. Add unit tests covering the issue symptom and edge cases. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Author
|
@yegor256 take a look, please |
Member
|
@rultor merge |
Contributor
Contributor
|
@roman-shaposhnikov Great work on your contribution! 🎉 You've earned +16 points and your running score is now +16. We appreciate your commitment to quality over speed - keep up the excellent contributions! Don't forget to check your Zerocracy account for updates. |
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.
Closes #782.
Windows CI failed
test/commands/test_foreign.jswith:JSON.parseconsumed a valid prefix and then tripped on trailing bytes after the closing].Fix
src/commands/foreign.jsno longer feeds the raw file toJSON.parse. It scans for the first balanced[...]array (string-literalaware, BOM-tolerant) and parses only that — any trailing bytes from a non-atomic writer are ignored.
Tests
New
test/test_foreign_parse.jscovers clean JSON, BOM / leading whitespace, the #782 symptom (valid array + a second concatenatedarray at "line N column 2"), nested arrays inside string values, and a negative case. The existing
test/commands/test_foreign.jsintegrationtest still passes.
Caveat
The corruption does not reproduce locally on Linux (the plugin writes clean JSON), so this is consumer-side hardening, not a
root-cause fix — the underlying race likely lives in upstream
tojos/ Maven plugin and deserves its own investigation. Supersedes thecosmetic-only draft #785.