Repository navigation
config: a config.json (and the other JSON files read past a BOM) saved as UTF-16 is read, not refused as invalid JSON - #276
Conversation
…d as UTF-16 is read, not refused as invalid JSON Windows PowerShell 5.1 writes UTF-16LE with a byte-order mark for `ConvertTo-Json | Out-File config.json` and for `>`. readConfigFile read the file as UTF-8, so such a config.json stopped every command with "is not valid JSON", though Notepad shows valid JSON. config.ts gains readText: a file that starts with a UTF-16LE or UTF-16BE byte-order mark is decoded from UTF-16; any other is read as UTF-8 past a UTF-8 mark, as withoutBom did. A UTF-16 file without a mark is not guessed at. Every reader that went through withoutBom now goes through readText: config.json (readConfigFile, and the receiver's live re-read in app.ts), machines.json and the queue files (control/state.ts), labels/marks/limits.json (docFile), color themes and view, skin and plugin manifests. The next write of config.json is UTF-8 without a mark, as with a UTF-8 mark. Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
|
#280 also changes |
Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
|
The BOM-marked UTF-16 JSON reading fix still applies to SessionPipe GUI v0.8.18. Merged current Added the previously deferred Unreleased changelog entry. Validation on this head, macOS / Node 22.23.2:
GitHub CI run 47453782790 for head Also checked the combined source/test changes from all 19 refreshed PRs on the same main: no source conflicts; typecheck, lint and build passed; all 252 unit-test files passed (3,439 tests, two skipped). This was a local integration check, separate from the individual PR run above. Release-note entries may still need combining as PRs land. |
Updated against v0.8.18 / main
d16a2c01on 2026-12-05. Current validation and refresh details.What
A
config.jsonsaved as UTF-16 with a byte-order mark is now read. Before this change the GUI stopped every command with "config.jsonis not valid JSON, so it was not written over", though Notepad shows valid JSON. The same holds for the other files the GUI already reads past a UTF-8 byte-order mark:control/machines.jsonand the queue files,labels.json/marks.json/limits.json, color themes, and view, skin and plugin manifests. The next write ofconfig.jsonis UTF-8 without a mark, as with a UTF-8 mark (#92).Why
Windows PowerShell 5.1 writes UTF-16LE with a byte-order mark (
FF FE) forConvertTo-Json | Out-File config.jsonand for>. The README and the authoring guides tell people to editconfig.jsonby hand (disabled,enabled, the key).readConfigFileread the file as UTF-8, so the text began��{\0"\0…and did not parse. The error gave no position and no cause the person could see.config.tsgainsreadText(file):FF FEis decoded as UTF-16LE.FE FF(-Encoding BigEndianUnicode) is byte-swapped and then decoded as UTF-16LE. This avoids autf-16bedecoder, which a Node built without full ICU does not have.withoutBomdid.A UTF-16 file without a mark is not guessed at: it still does not parse. A cut-short UTF-16 file (an odd number of bytes) ends in U+FFFD, so it is refused and left byte for byte. Neither
FF FEnorFE FFcan start valid UTF-8, so no file that read before reads differently now.Every reader that went through
withoutBomnow goes throughreadText:readConfigFile(config.ts).readGuiConfig,writeChanged,writeGuiConfig,key renewand the search CLI's history setting all read through it.config.json(app.tsfileText). It is compared withownText/lastRead, which are now both decoded text. A file that holds the same JSON in another encoding starts nothing, as an equal file did before.readMachinesFileandreadJson(queue files) in control/state.ts.docFile(labels, marks, limits).readColorThemes.readManifestOf(view, skin and plugin manifests).writeIfOtherstill compares raw UTF-8 bytes, so a UTF-16 file is never taken for "already holds this" and the next write converts it.Not changed here:
readLabelsinserver/search/cli.tsreadslabels.jsonwith a plainJSON.parseand never read past a UTF-8 mark either (named as a follow-up in ui: a labels.json, marks.json or limits.json with a byte-order mark is read past it #171). Adding mark handling there is a separate change to the search CLI.plugins/settings.ts,plugins/host.ts,runfile.ts,localDoor.ts,sources/outbox.ts,ui/skillsCore.ts,control/files.ts) read files the GUI writes itself, not files people are told to edit.Shared files with my open pull requests: #269 also touches
server/skins/skins.test.ts.git merge-tree --write-treeof this branch with #269's head (1bc8af9) has no conflicts.An entry is now included under Unreleased in
CHANGELOG.md. Other open PRs also add release notes; those entries may need combining as the PRs land.Original proof (before the v0.8.18 refresh)
New tests:
server/config.test.ts: reads a UTF-16LE and a UTF-16BEconfig.jsonwith CRLF and a non-ASCII value. The read leaves the file byte for byte; the next write is UTF-8 and keeps the values. A cut-short UTF-16 file and UTF-16 without a mark stop with "is not valid JSON", leaving the file byte for byte and never quoting the token.server/keyRules.test.ts: a key written by hand as UTF-16 while the receiver runs is taken.server/control/machines-file.test.ts: a UTF-16machines.jsonkeeps its machine and queue, and a UTF-16 queue file is kept (on main it was deleted at start).server/ui/docFile.test.ts,server/ui/ui.test.ts,server/skins/skins.test.ts: a UTF-16 document, color theme andskin.jsonare read.With the six source files from origin/main (6165bed), the same tests:
On main,
config.jsonfails withConfigError: …/config.json is not valid JSON, so it was not written over, and the manifest, theme and document fail withUnexpected token '�', "��{ " … is not valid JSON. The "cut short or without a byte-order mark" test passes on both main and this branch; it guards against guessing.On this branch:
npm run typecheckexits 0.npm run buildexits 0.npm run lintexits 0 withChecked 983 files … Found 135 warnings.and no errors;npx biome checkon the 12 changed files reports nothing.npm testhas one failure, a timeout in a test this change does not touch:A full
npx vitest runon unmodified origin/main (6165bed) fails the same test the same way (1 failed | 247 passed (248)). Run on its own, it passes on both main and this branch (11 passed (11)).Checklist
git commit -s): the DCO is the only paperwork.npm run typecheck && npm run lint && npm testpass;npm run test:e2efor a UI change. (Not a UI change.npm test: one timeout that also fails on main, above.)// SPDX-License-Identifier: Apache-2.0. (No new files.)--demo).shared/*names the wire-contract change in the description. (No change toshared/.)CHANGELOG.md.