Merge pull request #1453 from khaledhosny/volt-stop-at-end
[voltLib] Don’t try to read past END
This commit is contained in:
commit
017523414c
@ -44,10 +44,7 @@ class Parser(object):
|
|||||||
func = getattr(self, PARSE_FUNCS[self.cur_token_])
|
func = getattr(self, PARSE_FUNCS[self.cur_token_])
|
||||||
statements.append(func())
|
statements.append(func())
|
||||||
elif self.is_cur_keyword_("END"):
|
elif self.is_cur_keyword_("END"):
|
||||||
if self.next_token_type_ is not None:
|
break
|
||||||
raise VoltLibError("Expected the end of the file",
|
|
||||||
self.cur_token_location_)
|
|
||||||
return self.doc_
|
|
||||||
else:
|
else:
|
||||||
raise VoltLibError(
|
raise VoltLibError(
|
||||||
"Expected " + ", ".join(sorted(PARSE_FUNCS.keys())),
|
"Expected " + ", ".join(sorted(PARSE_FUNCS.keys())),
|
||||||
@ -602,6 +599,8 @@ class Parser(object):
|
|||||||
self.cur_token_type_, self.cur_token_, self.cur_token_location_ = (
|
self.cur_token_type_, self.cur_token_, self.cur_token_location_ = (
|
||||||
self.next_token_type_, self.next_token_, self.next_token_location_)
|
self.next_token_type_, self.next_token_, self.next_token_location_)
|
||||||
try:
|
try:
|
||||||
|
if self.is_cur_keyword_("END"):
|
||||||
|
raise StopIteration
|
||||||
(self.next_token_type_, self.next_token_,
|
(self.next_token_type_, self.next_token_,
|
||||||
self.next_token_location_) = self.lexer_.next()
|
self.next_token_location_) = self.lexer_.next()
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
|
@ -1028,6 +1028,14 @@ class ParserTest(unittest.TestCase):
|
|||||||
("CMAP_FORMAT", (3, 1, 4)))
|
("CMAP_FORMAT", (3, 1, 4)))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_stop_at_end(self):
|
||||||
|
[def_glyph] = self.parse(
|
||||||
|
'DEF_GLYPH ".notdef" ID 0 TYPE BASE END_GLYPH END\0\0\0\0'
|
||||||
|
).statements
|
||||||
|
self.assertEqual((def_glyph.name, def_glyph.id, def_glyph.unicode,
|
||||||
|
def_glyph.type, def_glyph.components),
|
||||||
|
(".notdef", 0, None, "BASE", None))
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.tempdir = None
|
self.tempdir = None
|
||||||
self.num_tempfiles = 0
|
self.num_tempfiles = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user