Skip to content

fix(#782): tolerate trailing bytes when reading eo-foreign.json#944

Merged
rultor merged 1 commit into
objectionary:masterfrom
roman-shaposhnikov:782
May 18, 2026
Merged

fix(#782): tolerate trailing bytes when reading eo-foreign.json#944
rultor merged 1 commit into
objectionary:masterfrom
roman-shaposhnikov:782

Conversation

@roman-shaposhnikov

@roman-shaposhnikov roman-shaposhnikov commented May 17, 2026

Copy link
Copy Markdown
Contributor

Closes #782.

Windows CI failed test/commands/test_foreign.js with:

Unexpected non-whitespace character after JSON at position 11819 (line 251 column 2)

JSON.parse consumed a valid prefix and then tripped on trailing bytes after the closing ].

Fix

src/commands/foreign.js no longer feeds the raw file to JSON.parse. It scans for the first balanced [...] array (string-literal
aware, BOM-tolerant) and parses only that — any trailing bytes from a non-atomic writer are ignored.

Tests

New test/test_foreign_parse.js covers clean JSON, BOM / leading whitespace, the #782 symptom (valid array + a second concatenated
array at "line N column 2"), nested arrays inside string values, and a negative case. The existing test/commands/test_foreign.js integration
test 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 the
cosmetic-only draft #785.

…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>
@roman-shaposhnikov

Copy link
Copy Markdown
Contributor Author

@yegor256 take a look, please

@yegor256

Copy link
Copy Markdown
Member

@rultor merge

@rultor

rultor commented May 18, 2026

Copy link
Copy Markdown
Contributor

@rultor merge

@yegor256 OK, I'll try to merge now. You can check the progress of the merge here.

@rultor rultor merged commit 22ec88f into objectionary:master May 18, 2026
16 checks passed
@rultor

rultor commented May 18, 2026

Copy link
Copy Markdown
Contributor

@rultor merge

@yegor256 Done! FYI, the full log is here (took me 8min).

@0crat

0crat commented May 18, 2026

Copy link
Copy Markdown

@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.

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.

foreign test fails with a JSON parsing error.

4 participants