diff options
-rw-r--r-- | locale/en_US.sh | 2 | ||||
-rw-r--r-- | src/substvars.sh | 25 |
2 files changed, 25 insertions, 2 deletions
diff --git a/locale/en_US.sh b/locale/en_US.sh index 77569ef..56f7da8 100644 --- a/locale/en_US.sh +++ b/locale/en_US.sh @@ -37,6 +37,8 @@ msg_prokit_temp_rmdir_fail='Failed to remove temporary directory "%s"' # src/substvars.sh msg_prokit_substvar_invalid='Invalid substitution variable name "%s"' msg_prokit_substvar_deep_nesting='Possible recursion in substitutions' +msg_prokit_substvar_invalid='Invalid substitution variable "%s"' +msg_prokit_substvar_unknown='Unknown substitution variable "%s"' # src/control.sh msg_prokit_control_empty_line='empty line' 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 |