Skip to content

Commit 1d78d98

Browse files
author
Tom Brandenburg
committed
fix: resolve shell script escaping and variable export issues
- Fix shell script over-escaping in code node generator for /bin/bash -c commands - Preserve shell syntax like ${VAR:-default} in bash scripts - Add export to set_var function for subshell variable access - Fix circuit-breaker-template unbound variable by not escaping shell parameter expansion - Improve debug logging to show export status
1 parent 324b630 commit 1d78d98

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/generation/generators/code-node.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,22 @@ export class CodeNodeGenerator extends BaseNodeGenerator {
7272
let fullCommand = this.processTemplateVariablesForSubshell(String(command), node.id);
7373

7474
if (Array.isArray(args) && args.length > 0) {
75+
// Special handling for shell interpreters with script arguments
76+
const isShellCommand = String(command).includes('bash') || String(command).includes('sh');
77+
const stringArgs = args.map(arg => String(arg));
78+
const hasCFlag = stringArgs.includes('-c');
79+
7580
// Process each argument for subshell context
76-
const processedArgs = args.map(arg => {
81+
const processedArgs = args.map((arg, index) => {
7782
const argStr = String(arg);
7883
const processed = this.processTemplateVariablesForSubshell(argStr, node.id);
84+
85+
// Don't escape shell script content for bash -c commands
86+
if (isShellCommand && hasCFlag && index > 0 && stringArgs[index - 1] === '-c') {
87+
// This is a shell script - preserve shell syntax by not escaping
88+
return `"${processed}"`;
89+
}
90+
7991
// Quote arguments that might contain spaces or special chars
8092
if (this.needsQuoting(processed)) {
8193
const escaped = this.escapeShellValueSmart(processed);

src/generation/shell-generator.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,13 @@ set_var() {
325325
local value="$2"
326326
local node_id="\${3:-root}"
327327
328-
# Set the variable globally
328+
# Set the variable globally and export it for subshells
329329
declare -g "$var_name"="$value"
330+
export "$var_name"
330331
331332
# Debug logging when FLOWSH_DEBUG=true
332333
if [[ "\${FLOWSH_DEBUG:-false}" == "true" ]]; then
333-
echo "[DEBUG] $node_id: SET $var_name = '$value'" >&2
334+
echo "[DEBUG] $node_id: SET $var_name = '$value' (exported)" >&2
334335
fi
335336
}
336337

0 commit comments

Comments
 (0)