Permalink
Browse files

Fix crash in an error case: the function name word has quotes.

  • Loading branch information...
Andy Chu
Andy Chu committed Oct 18, 2017
1 parent 77f7e9b commit d52e4a475396bd08a3d7f70feae2b91d134ae97e
Showing with 11 additions and 9 deletions.
  1. +3 −4 core/word.py
  2. +1 −2 osh/cmd_parse.py
  3. +7 −3 osh/cmd_parse_test.py
View
@@ -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
View
@@ -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
View
@@ -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.