summaryrefslogtreecommitdiffstats
path: root/src
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 /src
parent7ef055e48c966fc1171cd60f3e9f34a18d47f91d (diff)
substvars(): Sync with opkbuild
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