From 83bd3c9bc6547d050808751c8165dc47931149d2 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Sat, 10 May 2003 18:26:20 +0000 Subject: [PATCH] Interpolate the null string for illegal list subscripts. git-svn-id: http://scons.tigris.org/svn/scons/trunk@678 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 3 +++ src/engine/SCons/Util.py | 4 ++-- src/engine/SCons/UtilTests.py | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 7717ce64..d4416045 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -77,6 +77,9 @@ RELEASE 0.14 - XXX - Add internal SCons.Node.FS.{Dir,File}.Entry() methods. + - Interpolate the null string if an out-of-range subscript is used + for a construction variable. + From Damyan Pepper: - Quote the "Entering directory" message like Make. diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 8d81437f..3b979074 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -456,7 +456,7 @@ def scons_subst_list(strSubst, env, mode=SUBST_RAW, target=None, source=None): key = key[1:-1] try: e = eval(key, global_vars, local_vars) - except NameError: + except (IndexError, NameError, TypeError): return '\0\5' if callable(e): # We wait to evaluate callables until the end of everything @@ -524,7 +524,7 @@ def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None): key = key[1:-1] try: e = eval(key, global_vars, local_vars) - except NameError: + except (IndexError, NameError, TypeError): return '\0\5' if callable(e): e = e(target=target, source=source, env=env, diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index a48b3021..84655a9b 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -227,6 +227,20 @@ class UtilTestCase(unittest.TestCase): newcom = scons_subst("$FOO $BAZ $BAR", DummyEnv(glob)) assert newcom == "BAR $FOO BAR", newcom + # Test that we don't blow up even if they subscript something + # in ways they "can't." + glob = { "FOO" : "BAR", + "NOTHING" : "" , + "NONE" : None } + newcom = scons_subst("${FOO[0]}", DummyEnv(glob)) + assert newcom == "B", newcom + newcom = scons_subst("${FOO[7]}", DummyEnv(glob)) + assert newcom == "", newcom + newcom = scons_subst("${NOTHING[1]}", DummyEnv(glob)) + assert newcom == "", newcom + newcom = scons_subst("${NONE[2]}", DummyEnv(glob)) + assert newcom == "", newcom + def test_splitext(self): assert splitext('foo') == ('foo','') assert splitext('foo.bar') == ('foo','.bar') -- 2.26.2