From 7e4140fca4be9dab349df08297fa1cbc0165a4bd Mon Sep 17 00:00:00 2001 From: Idan Kamara Date: Sat, 27 Sep 2014 18:55:39 -0700 Subject: [PATCH] tokenizer: don't go out of bounds when checking for += in words --- bashlex/tokenizer.py | 2 +- setup.py | 2 +- tests/test-tokenizer.py | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bashlex/tokenizer.py b/bashlex/tokenizer.py index a2220f55..f53ef9fc 100644 --- a/bashlex/tokenizer.py +++ b/bashlex/tokenizer.py @@ -977,7 +977,7 @@ def legalvariablechar(x): return i # XXX general.c 289 - if c == '+' and value[i+1] == '=': + if c == '+' and i + 1 < len(value) and value[i+1] == '=': return i+1 if not legalvariablechar(c): diff --git a/setup.py b/setup.py index 67df444b..1d647e25 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='bashlex', - version='0.2', + version='0.3', url='https://github.com/idank/bashlex.git', license='GPLv3+', author='Idan Kamara', diff --git a/tests/test-tokenizer.py b/tests/test-tokenizer.py index 435a9c11..bfdc544b 100644 --- a/tests/test-tokenizer.py +++ b/tests/test-tokenizer.py @@ -241,6 +241,17 @@ def test_assignment(self): t(tt.ASSIGNMENT_WORD, 'a=b', [0, 3], flags=set([flags.word.NOSPLIT, flags.word.ASSIGNMENT]))]) + s = 'a+=b' + self.assertTokens(s, [ + t(tt.ASSIGNMENT_WORD, 'a+=b', [0, 4], + flags=set([flags.word.NOSPLIT, flags.word.ASSIGNMENT]))]) + + def test_plus_at_end_of_word(self): + s = 'a+ b' + self.assertTokens(s, [ + t(tt.WORD, 'a+', [0, 2]), + t(tt.WORD, 'b', [3, 4])]) + def test_heredoc(self): s = 'a <