summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/substvars.sh25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/substvars.sh b/src/substvars.sh
index 36ec308..ee845e3 100644
--- a/src/substvars.sh
+++ b/src/substvars.sh
@@ -87,9 +87,30 @@ substvars()
fi
old_rhs="${rhs}"
+ # Validate the variable name.
+ case "${name}" in *[!A-Za-z0-9-]* | '')
+ warn "$(get_msg 'substvar_invalid')" "${name}"
+ # Remove the variable expansion altogether. We can't
+ # just leave the variable unexpanded, because the
+ # presence of the "${" characters would cause this
+ # parser to loop infinitely.
+ string="${lhs}${rhs}"
+ continue
+ esac
+
# Perform the substitution.
- name="$(printf '%s\n' "${name}" | tr 'A-Z-' 'a-z_')"
- value="$(eval "printf '%s\n' \"\${substvar_${name}}\"")"
+ name_tr="$(printf '%s' "${name}" | tr 'A-Z-' 'a-z_')"
+ package="$(printf '%s' "${package}" | tr 'A-Z' 'a-z' | \
+ tr -dC 'a-z0-9')"
+ if eval "[ x\"\${substvar_${name_tr}:+set}\" = x'set' ]"
+ then
+ name_tr="substvar_${name_tr}"
+ else
+ warn "$(get_msg 'substvar_unknown')" "${name}"
+ string="${lhs}${rhs}"
+ continue
+ fi
+ value="$(eval "printf '%s' \"\${${name_tr}}\"")"
string="${lhs}${value}${rhs}"
depth=$((${depth} + 1))
done