Skip to content

Commit

Permalink
Fix crash in an error case: the function name word has quotes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Chu committed Oct 18, 2017
1 parent 77f7e9b commit d52e4a4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
7 changes: 3 additions & 4 deletions core/word.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,9 @@ def AsFuncName(w):
if not ok:
return False, ''
if quoted:
# TODO: Return False with error string
if len(self.parts) != 1:
raise RuntimeError(
"Function names should not have quotes, got: %s", self.parts)
# Function names should not have quotes
if len(w.parts) != 1:
return False, ''
return True, s


Expand Down
3 changes: 1 addition & 2 deletions osh/cmd_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,8 +1120,7 @@ def ParseFunctionDef(self):

ok, name = word.AsFuncName(self.cur_word)
if not ok:
self.AddErrorContext("Invalid function name: %r",
self.cur_word, word=self.cur_word)
self.AddErrorContext('Invalid function name', word=self.cur_word)
return None
self._Next() # skip function name

Expand Down
10 changes: 7 additions & 3 deletions osh/cmd_parse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1250,18 +1250,22 @@ def testArith(self):
err = _assertParseCommandListError(self, '(( 1 + ))')

def testArraySyntax(self):
"""Enumerating errors in arith_parse.py."""
err = _assertParseCommandListError(self, 'A= (1 2)')

def testRedirectsInAssignment(self):
"""Enumerating errors in arith_parse.py."""
err = _assertParseCommandListError(self, 'x=1 >/dev/null')
err = _assertParseCommandListError(self, 'declare x=1 >/dev/null')

def testEofInDoubleQuoted(self):
"""Enumerating errors in arith_parse.py."""
err = _assertParseCommandListError(self, 'foo="" echo "bar ')

def testQuotesInFunctionName(self):
err = _assertParseCommandListError(self, """\
foo"bar" () {
echo hi
}
""")


if __name__ == '__main__':
unittest.main()

0 comments on commit d52e4a4

Please sign in to comment.