From 7f7ae1bef10bcf186e21a3e923b9756a50ecf52b Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 24 Jun 2026 10:14:27 +0300 Subject: Fix: shell-quote rewritten TEMPLATE_DIR so spaced source paths source cleanly init_config rewrote the TEMPLATE_DIR line via awk as a bare, unquoted literal when running --init from a source checkout. A source-root path containing a space (or any shell metacharacter) produced a config that aborts on source under "set -euo pipefail": the value was word-split, truncating the path and running its tail as a command (exit 127), leaving TEMPLATE_DIR empty and breaking every subsequent action. Emit the rewritten value as a single-quoted assignment, escaping any embedded single quote as '\'', so the generated shuriken.conf round-trips through sourcing regardless of spaces or single quotes. The non-rewrite path (installed /etc/default/shuriken) is unchanged. Regenerated bin/shuriken via just build. Tests: test_init and test_init_with_hash_in_source_path now assert the SOURCED TEMPLATE_DIR (the real contract) instead of the literal line, and a new test_init_with_space_in_source_path covers the spaced-path regression. Co-Authored-By: Claude Opus 4.8 --- src/lib/paths.source.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/paths.source.sh b/src/lib/paths.source.sh index d0db74b..eeea068 100644 --- a/src/lib/paths.source.sh +++ b/src/lib/paths.source.sh @@ -121,9 +121,16 @@ init_config() { && "$default_rc_file" = "$source_root/src/shuriken.default.conf" ]]; then source_template_dir="$source_root/share/templates/default" rewritten_rc_file=$(mktemp "${rc_file}.XXXXXX") + # Emit the rewritten TEMPLATE_DIR as a single-quoted assignment so the + # generated config sources cleanly under "set -euo pipefail" even when + # the source-checkout path contains spaces or other shell metacharacters + # (an unquoted value would be word-split on source, truncating the path + # and running its tail as a command -> exit 127). Any embedded single + # quote is closed, escaped as '\'', and reopened so the literal survives. if ! awk -v template_dir="$source_template_dir" \ '/^TEMPLATE_DIR=/ { - print "TEMPLATE_DIR=" template_dir + gsub(/'\''/, "'\''\\'\'''\''", template_dir) + print "TEMPLATE_DIR='\''" template_dir "'\''" next } { print }' "$rc_file" > "$rewritten_rc_file"; then -- cgit v1.2.3