Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Work around Windows incompatibilities in
shell-quote
Fixes #143. The nodejs library shell-quote does not escape Windows paths correctly. An LGTM'd PR exists here[1]. Since we need it, we re-implement this for Windows paths. [1]: https://github.com/substack/node-shell-quote/pull/34/
- Loading branch information
Showing
8 changed files
with
123 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,19 @@ | ||
import * as shell from "shell-quote"; | ||
|
||
export function quotePath(path: string): string { | ||
if (process.platform === "win32") { | ||
return quoteWindowsPath(path); | ||
} else { | ||
return shell.quote([path]); | ||
} | ||
} | ||
|
||
export function quoteWindowsPath(path: string): string { | ||
// Unescape paths for Windows. Taken directly from[1], an unmerged, but LGTM'd PR to the | ||
// official library. | ||
// | ||
// [1]: https://github.com/substack/node-shell-quote/pull/34 | ||
|
||
path = String(path).replace(/([A-z]:)?([#!"$&'()*,:;<=>?@\[\\\]^`{|}])/g, "$1\\$2"); | ||
return path.replace(/\\\\/g, "\\"); | ||
} |
This file contains 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,17 @@ | ||
import * as assert from "assert"; | ||
import * as path from "../path"; | ||
|
||
describe("path.quoteWindowsPath", () => { | ||
it("escapes Windows path with drive prefix correctly", () => { | ||
const p = path.quoteWindowsPath("C:\\Users\\grace hopper\\AppData\\Local\\Temp"); | ||
assert.equal(p, "C:\\Users\\grace hopper\\AppData\\Local\\Temp"); | ||
}); | ||
it("escapes Windows path with no drive prefix correctly", () => { | ||
const p = path.quoteWindowsPath("\\Users\\grace hopper\\AppData\\Local\\Temp"); | ||
assert.equal(p, "\\Users\\grace hopper\\AppData\\Local\\Temp"); | ||
}); | ||
it("escapes relative Windows path correctly", () => { | ||
const p = path.quoteWindowsPath("Users\\grace hopper\\AppData\\Local\\Temp"); | ||
assert.equal(p, "Users\\grace hopper\\AppData\\Local\\Temp"); | ||
}); | ||
}); |
This file contains 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 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 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