GeezerVison is showing github.com — fix(opencode,core): close audit-v12 wave I-A shell classification fin… · anomalyco/opencode@3f69dad
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/core/src/util/wildcard.ts +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,6 +23,19 @@ export function unquote(value: string) { |
23 | 23 | let quote: "'" | '"' | undefined |
24 | 24 | for (let index = 0; index < value.length; index++) { |
25 | 25 | const char = value[index] |
| 26 | + // Bash deletes `\<newline>` line continuations before execution (`ca\<newline>t` |
| 27 | + // runs `cat`); single quotes keep the backslash, so exclude only those. |
| 28 | + if (char === "\\" && quote !== "'") { |
| 29 | + const next = value[index + 1] |
| 30 | + if (next === "\n") { |
| 31 | + index++ |
| 32 | + continue |
| 33 | + } |
| 34 | + if (next === "\r" && value[index + 2] === "\n") { |
| 35 | + index += 2 |
| 36 | + continue |
| 37 | + } |
| 38 | + } |
26 | 39 | if (quote) { |
27 | 40 | if (char === quote) { |
28 | 41 | quote = undefined |
|
Collapse file
Copy file name to clipboardExpand all lines: packages/core/test/wildcard.test.ts +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -112,6 +112,13 @@ describe("Wildcard.unquote", () => { |
112 | 112 | expect(Wildcard.matchStrict('"cat" notes.txt', "cat *")).toBe(true) |
113 | 113 | }) |
114 | 114 |
|
| 115 | + test("deletes backslash-newline line continuations like bash", () => { |
| 116 | + expect(Wildcard.unquote("ca\\\nt")).toBe("cat") |
| 117 | + expect(Wildcard.unquote("\\\ncat")).toBe("cat") |
| 118 | + expect(Wildcard.unquote('"a\\\nb"')).toBe("ab") |
| 119 | + expect(Wildcard.unquote("'a\\\nb'")).toBe("a\\\nb") |
| 120 | + }) |
| 121 | + |
115 | 122 | if (process.platform !== "win32") { |
116 | 123 | test("unescapes backslash traversal as the shell would", () => { |
117 | 124 | expect(Wildcard.unquote("..\\/etc")).toBe("../etc") |
|