Skip to content

Commit

Permalink
tokenizer: don't go out of bounds when checking for += in words
Browse files Browse the repository at this point in the history
  • Loading branch information
idank committed Sep 28, 2014
1 parent 612e02b commit 7e4140f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bashlex/tokenizer.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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',
Expand Down
11 changes: 11 additions & 0 deletions tests/test-tokenizer.py
Expand Up @@ -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 <<EOF'
self.assertTokens(s, [
Expand Down

0 comments on commit 7e4140f

Please sign in to comment.