summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-04-23 13:23:52 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-04-23 13:23:52 (EDT)
commit2278170d29b0c5a61017a99b11b54b3abb92d57f (patch)
tree6be9d87f7b5c9a2f24a061f7280e3638d6472b91
parent7ef055e48c966fc1171cd60f3e9f34a18d47f91d (diff)
substvars(): Sync with opkbuild
-rw-r--r--locale/en_US.sh2
-rw-r--r--src/substvars.sh25
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