Permalink
Browse files

Fix uncaught exception parsing 'for ('

From ~/git/other/illumos-gate/usr/src/cmd/ypcmd/multi.awk.sh
  • Loading branch information...
Andy Chu
Andy Chu committed Oct 18, 2017
1 parent 58c4884 commit bc3a9fd44a8d9b46fb85448b69cf845b809301ff
Showing with 18 additions and 2 deletions.
  1. +8 −0 core/word.py
  2. +2 −2 osh/cmd_parse.py
  3. +8 −0 osh/cmd_parse_test.py
View
@@ -5,6 +5,9 @@
import sys
from osh import ast_ as ast
from core.id_kind import Id, Kind, LookupKind
from core import util
p_die = util.p_die
word_e = ast.word_e
word_part_e = ast.word_part_e
@@ -85,6 +88,11 @@ def StaticEval(w):
"""
ret = ''
quoted = False
# e.g. for ( instead of for (( is a token word
if w.tag != word_e.CompoundWord:
return False, ret, quoted
for part in w.parts:
ok, s, q = _EvalWordPart(part)
if not ok:
View
@@ -768,11 +768,11 @@ def _ParseForEachLoop(self):
ok, iter_name, quoted = word.StaticEval(self.cur_word)
if not ok or quoted:
self.AddErrorContext(
"Invalid for loop variable: %s", self.cur_word, word=self.cur_word)
"Invalid for loop variable", word=self.cur_word)
return None
if not VAR_NAME_RE.match(iter_name):
self.AddErrorContext(
"Invalid for loop variable name: %s", self.cur_word, word=self.cur_word)
"Invalid for loop variable name", word=self.cur_word)
return None
node.iter_name = iter_name
self._Next() # skip past name
View
@@ -1266,6 +1266,14 @@ def testQuotesInFunctionName(self):
}
""")
def testForLoopName(self):
err = _assertParseCommandListError(self, """\
for ( i = 1; i < 10; i++ )
""")
err = _assertParseCommandListError(self, """\
for = in a
""")
if __name__ == '__main__':
unittest.main()

0 comments on commit bc3a9fd

Please sign in to comment.