]> git.ipfire.org Git - people/ms/network.git/commitdiff
list: fix a bug
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Wed, 19 Jul 2017 13:21:51 +0000 (15:21 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 19 Jul 2017 17:09:35 +0000 (19:09 +0200)
When the list is called "list" we have a problem because
${list}="list"
and ${!list}="list"
This creates effects nobody wants and which are also not so easy to understand.
To avoid such problems in the future we now throw an assertation when the list is called list.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.list

index 26ba6c34e4185c25488b90a619f472048de32605..ff73b04e0f737474cd736c823cb8096d38059137 100644 (file)
@@ -25,6 +25,7 @@
 list_append() {
        local list=${1}
        assert isset list
+       assert [ ${list} != "list" ]
        shift
 
        local arg
@@ -40,6 +41,7 @@ list_append_one() {
        shift
 
        assert isset list
+       assert [ ${list} != "list" ]
 
        if [ -n "${!list}" ]; then
                printf -v ${list} -- "${!list} $@"
@@ -53,6 +55,7 @@ list_remove() {
        shift
 
        assert isset list
+       assert [ ${list} != "list" ]
 
        local _list k
        for k in ${!list}; do
@@ -127,6 +130,10 @@ list_join() {
        local list=${1}
        local delim=${2}
 
+       assert isset list
+       assert isset delim
+       assert [ ${list} != "list" ]
+
        local ret
        printf -v ret "${delim}%s" ${!list}