Repository navigation
fix(cli,vscode): quote for cmd.exe, and stop keeping four copies of the rule #661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
09d5cb6
fix(cli,vscode): quote for cmd.exe, and stop keeping four copies of t…
EtienneLescot 9f159f5
docs(cli): say what the Windows quoting does not promise
EtienneLescot a2cb7e1
feat(cli): say so when the installed n8nac is behind what is published
EtienneLescot d2f7a02
docs(troubleshooting): how to silence the update notice
EtienneLescot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /** | ||
| * Quote a path or argument for a shell we do not control. | ||
| * | ||
| * Nothing here is executed by us. The result is written into generated agent context | ||
| * and into CLI hints, for a person or an agent to paste into whatever shell they have. | ||
| * On Windows that is often `cmd.exe`, which does not strip POSIX single quotes: it hands | ||
| * them to the program verbatim, so a single-quoted path fails the moment it contains a | ||
| * space. Double quotes are understood by `cmd.exe`, PowerShell and bash alike, which | ||
| * makes them the only portable choice there. Windows forbids `"` in a path, so nothing | ||
| * needs escaping. | ||
| * | ||
| * POSIX keeps single quotes, which suppress every expansion; double quotes do not. | ||
| * | ||
| * Known ceiling: on Windows a value containing `$` or a backtick still expands under | ||
| * PowerShell and bash. Both are legal in Windows filenames, and no escaping satisfies | ||
| * cmd.exe, PowerShell and bash at once. Emit a relative path where you can. | ||
| * | ||
| * `platform` is injectable so the Windows branch is testable from any host. | ||
| */ | ||
| export function quoteShellArg(value: string, platform: NodeJS.Platform = process.platform): string { | ||
| return platform === 'win32' | ||
| ? `"${value}"` | ||
| : `'${value.replace(/'/g, `'\\''`)}'`; | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { quoteShellArg } from '../../src/utils/shell.js'; | ||
|
|
||
| // Written with an explicit BACKSLASH constant rather than source escapes. The escaping is | ||
| // what these tests are about, so a literal that a tool or an editor can quietly reshape | ||
| // would let the test agree with a broken implementation. | ||
| const BACKSLASH = String.fromCharCode(92); | ||
|
|
||
| describe('quoteShellArg', () => { | ||
| it('double-quotes on Windows, because cmd.exe does not strip single quotes', () => { | ||
| // Measured: `node '<path with a space>'` fails under cmd.exe with MODULE_NOT_FOUND, | ||
| // the quotes reaching node as part of the path. Double quotes work in cmd.exe, | ||
| // PowerShell and bash alike. | ||
| const p = 'C:' + BACKSLASH + 'dir with space' + BACKSLASH + 'e.js'; | ||
|
|
||
| expect(quoteShellArg(p, 'win32')).toBe('"' + p + '"'); | ||
| }); | ||
|
|
||
| it('single-quotes on POSIX, where they suppress every expansion', () => { | ||
| expect(quoteShellArg('/home/u/my dir/e.js', 'linux')).toBe("'/home/u/my dir/e.js'"); | ||
| }); | ||
|
|
||
| it('closes, escapes and reopens around an embedded single quote on POSIX', () => { | ||
| expect(quoteShellArg("/home/u/it's/e.js", 'darwin')) | ||
| .toBe("'/home/u/it'" + BACKSLASH + "''s/e.js'"); | ||
| }); | ||
|
|
||
| it('quotes a plain value on both, so callers never concatenate bare', () => { | ||
| expect(quoteShellArg('n8nac', 'win32')).toBe('"n8nac"'); | ||
| expect(quoteShellArg('n8nac', 'linux')).toBe("'n8nac'"); | ||
| }); | ||
| }); |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.