Repository navigation
fix(config): keep backslashes in config.toml paths - #607
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2494f7dc57
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
ktoml 0.7.1 writes a backslash followed by b, t, n, f, r, u, U or " as it is, so a Windows folder such as F:\Downloads\backup was read back with a backspace and every download failed. Write each backslash of a basic string as \u005C, and repair the control characters older versions left in Windows folder paths when loading, the add sheet's folders included. Fixes #605
83a9443 to
f1502e1
Compare
Fixes #605.
Cause
ktoml 0.7.1 (the latest release) escapes strings with
escapeBackslashes("btnfruU\""), which leaves a backslash alone when the next character is one ofb t n f r u U ", taking it for an escape that is already there. SoF:\Downloads\backupwas saved as"F:\\Downloads\backup"and read back asF:\Downloads<U+0008>ackup, and every download failed withInvalidPathException.\newcame back as a newline and\tempas a tab. A\Uor\unot followed by hex digits, as inC:\Users\…, made the whole file unreadable, so it was moved aside. A trailing backslash, or a backslash before", also produced invalid TOML. Reading works correctly; only writing was broken.Fix
ConfigStore.encodeencodes to ktoml's tree (TomlMainEncoder.encode) and writes every backslash of a basic string as the\u005Cescape, which ktoml's escaper leaves alone and any TOML reader decodes as\.FileConfigStoreandWebConfigStoreboth write through it. This covers every string, including names, hooks, proxy fields and arrays, with no per-field changes. Inline tables keep their pairs internal in ktoml, butKetchConfigwrites none.ConfigStore.decoderepairs files that older versions wrote. In Windows folder paths (the default directory, category folders,allowedDirectories, a hook's program and working directory, and the add sheet's remembered and pinned folders),\b,\t,\n,\fand\rare turned back into a backslash and the letter. A path counts as a Windows path when it starts with a drive (C:) or holds a\; category folders also count when the default directory is a Windows path. Windows refuses those control characters in names, while POSIX paths may contain them, so POSIX paths and other strings, such as hook arguments, are left alone.Not repaired: files the
\U/\ucase made unreadable were already moved aside toconfig.toml.broken-*by older versions, so this PR doesn't restore them.Tests
TomlBackslashesTest(commonTest): round-tripsF:\Downloads\backup,D:\Téléchargements\new,C:\new\tab\file,C:\Users\u\x, UNC paths, trailing backslashes, values with", and a literal\u005C. It also decodes a file in the old corrupted form and checks the repair. With the workaround turned off, the round-trip test fails.FileConfigStoreTest.save_windowsDownloadFolder_loadsUnchanged(jvmTest).:config:jvmTestand:config:iosSimulatorArm64Testpass.:config:wasmJsBrowserTestcompiles, but locally ChromeHeadless disconnects without reporting, and CI doesn't run it.Upstream
The bug is in ktoml's
escapeSpecialCharacters/escapeBackslashes(utils/SpecialCharacters.kt). I haven't filed an issue upstream yet. Once ktoml releases a fix, the workaround can be removed.