Skip to content

Commit f4573b3

Browse files
committed
fix(code-placeholders): skip continued newlines before comparison operands
1 parent d16e645 commit f4573b3

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎apps/sim/lib/execution/code-placeholders/shell.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,10 @@ function collectShellOccurrenceContexts<T extends ShellSpan>(
583583
frame.kind !== 'parameter'
584584
) {
585585
if (frame.conditional) {
586+
if (character === '\\' && code[index + 1] === '\n') {
587+
index += 2
588+
continue
589+
}
586590
if ((character === '&' || character === '|') && code[index + 1] === character) {
587591
endConditionalOperand(frame, index)
588592
}

‎apps/sim/scripts/test-shell-placeholders-e2e.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ async function compile(code: string, value: string): Promise<CompiledCodePlaceho
7070

7171
try {
7272
const arithmetic = [
73+
'[[ "{{KEY}}" \\\n -eq 0 ]]',
74+
'[[ \\\n "{{KEY}}" -eq 0 ]]',
7375
'time -p [[ "{{KEY}}" -eq 0 ]]',
7476
'coproc [[ "{{KEY}}" -eq 0 ]]; wait',
7577
'coproc worker [[ "{{KEY}}" -eq 0 ]]; wait',
@@ -150,6 +152,7 @@ try {
150152
}
151153

152154
const safePrograms = [
155+
'[[ "{{KEY}}" < \\\n -eq ]] || printf "%s\\n" ok',
153156
'time -p printf "%s\\n" "{{KEY}}" >/dev/null; printf "%s\\n" ok',
154157
'if (( BASH_VERSINFO[0] >= 4 )); then coproc printf "%s\\n" "{{KEY}}" [[ -eq 0 ]]; wait; fi; printf "%s\\n" ok',
155158
// biome-ignore lint/suspicious/noTemplateCurlyInString: shell parameter expansion

0 commit comments

Comments
 (0)