From 25ce1ca680ec877f47635affe8662edef26a210f Mon Sep 17 00:00:00 2001 From: Daveswo <969dwi@gmail.com> Date: Tue, 18 Aug 2026 02:32:20 -0400 Subject: [PATCH] Fix remaining two code-review findings, both verified live: 30-selfdiag.sh regex-metachar breakage (g++), fx.sh dedup collision on ] in candidate text --- contrib/fx/fx.sh | 10 ++++++++-- contrib/fx/sources.d/30-selfdiag.sh | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/contrib/fx/fx.sh b/contrib/fx/fx.sh index fdd028c..194b609 100755 --- a/contrib/fx/fx.sh +++ b/contrib/fx/fx.sh @@ -79,11 +79,17 @@ fx() { out=$("$src" "$cmd" 2>/dev/null) if [ -n "$out" ]; then printf '%s\n' "$out" | while IFS= read -r line; do - [ -n "$line" ] && printf '[%s] %s\n' "$label" "$line" + [ -n "$line" ] && printf '%s\t%s\n' "$label" "$line" done [ -n "$FX_AUTO" ] && break fi - done | awk -F'] ' '!seen[$2]++' + done | awk -F'\t' ' + { + label = $1 + text = substr($0, length(label) + 2) + if (!seen[text]++) print "[" label "] " text + } + ' ) chosen="" diff --git a/contrib/fx/sources.d/30-selfdiag.sh b/contrib/fx/sources.d/30-selfdiag.sh index ef0d376..5fe26df 100755 --- a/contrib/fx/sources.d/30-selfdiag.sh +++ b/contrib/fx/sources.d/30-selfdiag.sh @@ -21,8 +21,19 @@ cmd="$1" prog=$(printf '%s' "$cmd" | awk '{print $1}') [ -n "$prog" ] || exit 0 [ -n "$FX_OUTPUT" ] || exit 0 -printf '%s\n' "$FX_OUTPUT" | grep -qE "^[[:space:]]*${prog}[[:space:]]" || exit 0 + +# Literal prefix comparison (substr/index), never a regex built from +# $prog: proven broken live for program names containing ERE +# metacharacters -- e.g. "g++ foo.cpp" produced the pattern +# "^[[:space:]]*g++[[:space:]]", a malformed stacked-quantifier regex, +# and this source silently found nothing even when $FX_OUTPUT clearly +# started a line with "g++ ". Same fix applied to the emitted function +# below, since it runs the identical check on every future call. +printf '%s\n' "$FX_OUTPUT" | awk -v p="$prog" ' + { line = $0; sub(/^[ \t]*/, "", line); if (substr(line, 1, length(p) + 1) == p " ") { found = 1; exit } } + END { exit !found } +' || exit 0 cat <&1); ec=\$?; if [ \$ec -ne 0 ]; then sug=\$(printf '%s\\n' "\$out" | awk '/^[ \\t]*${prog}[ \\t]/{sub(/^[ \\t]*/,""); s=\$0} END{print s}'); if [ -n "\$sug" ]; then eval "command \$sug"; return \$?; fi; fi; printf '%s\\n' "\$out"; return \$ec; } +${prog}(){ out=\$(command ${prog} "\$@" 2>&1); ec=\$?; if [ \$ec -ne 0 ]; then sug=\$(printf '%s\\n' "\$out" | awk -v p="${prog}" '{ line=\$0; sub(/^[ \\t]*/,"",line); if (substr(line,1,length(p)+1)==p" ") s=line } END{print s}'); if [ -n "\$sug" ]; then eval "command \$sug"; return \$?; fi; fi; printf '%s\\n' "\$out"; return \$ec; } FIX