[feaLib] Raise exception when GSUB statement doesn't match a rule. (#1876)

* [feaLib] Raise exception when substitute statement doesnt match any of the rules. Add tests that trigger said exception.
This commit is contained in:
Tom 2020-04-16 16:10:03 +01:00 committed by GitHub
parent 6578b7c8a0
commit c70395fbdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View File

@ -826,8 +826,14 @@ class Parser(object):
'is not supported',
location)
# If there are remaining glyphs to parse, this is an invalid GSUB statement
if len(new) != 0:
raise FeatureLibError(
'Invalid substitution statement',
location
)
# GSUB lookup type 6: Chaining contextual substitution.
assert len(new) == 0, new
rule = self.ast.ChainContextSubstStatement(
old_prefix, old, old_suffix, lookups, location=location)
return rule

View File

@ -0,0 +1,13 @@
# Trigger a parser error in the function parse_substitute_ in order to improve the error message.
# Note that this is not a valid substitution, this test is made to trigger an error.
languagesystem latn dflt;
@base = [a e];
@accents = [acute grave];
feature abvs {
lookup lookup1 {
sub @base @accents by @base;
} lookup1;
} abvs;

View File

@ -1503,6 +1503,13 @@ class ParserTest(unittest.TestCase):
'Expected "by", "from" or explicit lookup references',
self.parse, "feature liga {substitute f f i;} liga;")
def test_substitute_invalid_statement(self):
self.assertRaisesRegex(
FeatureLibError,
"Invalid substitution statement",
Parser(self.getpath("GSUB_error.fea"), GLYPHNAMES).parse
)
def test_subtable(self):
doc = self.parse("feature test {subtable;} test;")
s = doc.statements[0].statements[0]