Permalink
Browse files
Fix crash in an error case: the function name word has quotes.
- Loading branch information...
Showing
with
11 additions
and
9 deletions.
-
+3
−4
core/word.py
-
+1
−2
osh/cmd_parse.py
-
+7
−3
osh/cmd_parse_test.py
|
|
@@ -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
|
|
|
|
|
|
|
|
|
|
|
|
@@ -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
|
|
|
|
|
|
|
|
|
@@ -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