Interpolate the null string for illegal list subscripts.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 10 May 2003 18:26:20 +0000 (18:26 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 10 May 2003 18:26:20 +0000 (18:26 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@678 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Util.py
src/engine/SCons/UtilTests.py

index 7717ce645697a362607db7b48c2865ae21a14305..d44160457d5e407dcbe71400b2c3c0b50779e916 100644 (file)
@@ -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.
index 8d81437f5eb43c1e2df4227103c3f48e52c4f9d3..3b979074e57b1e68c328935cee675cc0c652c577 100644 (file)
@@ -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,
index a48b3021d5542c369fa4b9c0f9fc52010bcdcd39..84655a9b1f3f7029df1ab961df2b14fe85fd7255 100644 (file)
@@ -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')