Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 6b1eaff

Browse files
starpitk8s-ci-robot
authored andcommitted
fix(packages/core): core command line parser does not handle octal escape
Also a few more fixes for handling of pipe stages that span lines
1 parent dc13b5c commit 6b1eaff

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

packages/core/src/repl/pipe-stages.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ export function splitIntoPipeStages(command: string): CommandLine['pipeStages']
4141
.replace(/^\s*>/, '')
4242
.trim()
4343

44-
const stages = split(command, false, undefined, '|', pipeStartIdx, pipeEndIdx).map(_ => split(_, false))
44+
const stages = split(command, false, undefined, '|', pipeStartIdx, pipeEndIdx).map(_ =>
45+
split(_, false).map(_ => _.replace(/\\\s/g, ''))
46+
)
4547

4648
return { prefix, stages, redirect }
4749
}

packages/core/src/repl/split.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ export const _split = (
7878
const removedLastOpenQuote: boolean[] = []
7979
let escapeActive = false
8080
for (let idx = startIdx; idx < endIdx; idx++) {
81-
let char = str.charAt(idx)
81+
const char = str.charAt(idx)
8282

83-
if (splitBy === ' ' && char === splitBy) {
83+
if (char === splitBy) {
8484
if (
85+
splitBy === ' ' &&
8586
process.platform === 'win32' &&
8687
idx < str.length - 3 &&
8788
/\w/.test(str.charAt(idx + 1)) &&
@@ -90,13 +91,16 @@ export const _split = (
9091
) {
9192
isWindowsDrivePath = true
9293
}
93-
} else if (!isWindowsDrivePath && char === '\\') {
94+
} else if (!isWindowsDrivePath && char === '\\' && (idx === endIdx - 1 || str.charAt(idx + 1) !== '0')) {
95+
// careful about \0 for octal escape
96+
9497
if (!escapeActive) {
9598
escapeActive = true
96-
char = str.charAt(++idx)
97-
if (!removeOuterQuotes) {
98-
cur += '\\'
99-
}
99+
continue
100+
// char = str.charAt(++idx)
101+
// if (!removeOuterQuotes) {
102+
// cur += '\\'
103+
// }
100104
} else {
101105
escapeActive = false
102106
cur += '\\'

0 commit comments

Comments
 (0)