Move the variable name validation regexes (for bug 211949) into
authorZac Medico <zmedico@gentoo.org>
Thu, 6 Mar 2008 00:23:32 +0000 (00:23 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 6 Mar 2008 00:23:32 +0000 (00:23 -0000)
filter-bash-environment.py instead of passing them in from bash.

svn path=/main/trunk/; revision=9445

bin/ebuild.sh
bin/filter-bash-environment.py

index 061e1961ca5be5e1718a8d459f08a483587c9005..542fca9e2f87378d3c3ea0d8845d8db5126d111e 100755 (executable)
@@ -1424,12 +1424,7 @@ filter_readonly_variables() {
                SANDBOX_DEBUG_LOG SANDBOX_DISABLED SANDBOX_LIB
                SANDBOX_LOG SANDBOX_ON"
        filtered_vars="${readonly_bash_vars} ${READONLY_PORTAGE_VARS}
-               BASH_[_[:alnum:]]* PATH
-               [[:digit:]][_[:alnum:]]*
-               .*[^_[:alnum:]].*"
-       # TODO: Take the above variable name validation and the below sed-based
-       #       declare -r filter and integrate them both directly into
-       #       filter-bash-environment.py.
+               BASH_[_[:alnum:]]* PATH"
        if hasq --filter-sandbox $* ; then
                filtered_vars="${filtered_vars} SANDBOX_[_[:alnum:]]*"
        else
@@ -1446,6 +1441,8 @@ filter_readonly_variables() {
                "
        fi
 
+       # TODO: Take the the below sed-based declare -r filter and integrate it
+       #       directly into filter-bash-environment.py.
        # The sed is to remove the readonly attribute from variables such as those
        # listed in READONLY_EBUILD_METADATA, since having any readonly attributes
        # persisting in the saved environment can be inconvenient when it
index 8f4b6d0cbc3bef767b8d8c889f4a438b6044febd..ab348d992393fa5906ac32dd7f9ef68695311c37 100755 (executable)
@@ -69,7 +69,7 @@ def filter_bash_environment(pattern, file_in, file_out):
                        here_doc_delim = re.compile("^%s$" % here_doc.group(1))
                        file_out.write(line)
                        continue
-               # Note: here-documents are handled before fuctions since otherwise
+               # Note: here-documents are handled before functions since otherwise
                # it would be possible for the content of a here-document to be
                # mistaken as the end of a function.
                if in_func:
@@ -103,7 +103,13 @@ if __name__ == "__main__":
                parser.error("Missing required PATTERN argument.")
        file_in = sys.stdin
        file_out = sys.stdout
-       var_pattern = "^(%s)$" % "|".join(args[0].split())
+       var_pattern = args[0].split()
+
+       # Filter invalid variable names that are not supported by bash.
+       var_pattern.append(r'\d.*')
+       var_pattern.append(r'.*\W.*')
+
+       var_pattern = "^(%s)$" % "|".join(var_pattern)
        filter_bash_environment(
                compile_egrep_pattern(var_pattern), file_in, file_out)
        file_out.flush()