Skip to content

Commit

Permalink
parser: allow script to be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleFromNVIDIA authored and idank committed Jan 17, 2024
1 parent 81a0580 commit ea0c135
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bashlex/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,8 @@ def parse(s, strictmode=True, expansionlimit=None, convertpos=False, proceedoner
'''
p = _parser(s, strictmode=strictmode, expansionlimit=expansionlimit, proceedonerror=proceedonerror)
parts = [p.parse()]
if parts[0] is None or isinstance(parts[0], str):
return []

class endfinder(ast.nodevisitor):
def __init__(self):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ def assertASTsEquals(self, s, expectedlist, **parserargs):
msg = 'ASTs not equal for %r\n\nresult:\n\n%s\n\n!=\n\nexpected:\n\n%s' % (s, result.dump(), expected.dump())
self.assertEqual(result, expected, msg)

def test_empty(self):
s = ''
self.assertASTsEquals(s, [])

s = '\n'
self.assertASTsEquals(s, [])

s = ' '
self.assertASTsEquals(s, [])

s = '# Comment'
self.assertASTsEquals(s, [])

s = '# Comment\n# Another comment'
self.assertASTsEquals(s, [])

def test_command(self):
s = 'a b c'
self.assertASTEquals(s,
Expand Down

0 comments on commit ea0c135

Please sign in to comment.