[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:
parent
6578b7c8a0
commit
c70395fbdb
@ -826,8 +826,14 @@ class Parser(object):
|
|||||||
'is not supported',
|
'is not supported',
|
||||||
location)
|
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.
|
# GSUB lookup type 6: Chaining contextual substitution.
|
||||||
assert len(new) == 0, new
|
|
||||||
rule = self.ast.ChainContextSubstStatement(
|
rule = self.ast.ChainContextSubstStatement(
|
||||||
old_prefix, old, old_suffix, lookups, location=location)
|
old_prefix, old, old_suffix, lookups, location=location)
|
||||||
return rule
|
return rule
|
||||||
|
13
Tests/feaLib/data/GSUB_error.fea
Normal file
13
Tests/feaLib/data/GSUB_error.fea
Normal 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;
|
@ -1503,6 +1503,13 @@ class ParserTest(unittest.TestCase):
|
|||||||
'Expected "by", "from" or explicit lookup references',
|
'Expected "by", "from" or explicit lookup references',
|
||||||
self.parse, "feature liga {substitute f f i;} liga;")
|
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):
|
def test_subtable(self):
|
||||||
doc = self.parse("feature test {subtable;} test;")
|
doc = self.parse("feature test {subtable;} test;")
|
||||||
s = doc.statements[0].statements[0]
|
s = doc.statements[0].statements[0]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user