feaLib: Drop glyph and class names length limit

These were implemented to follow FEA spec, but makeotf does not seem to
have a name length limit any more (or it has a very large one, I tested
a 600-character name and it was accepted).

Fixes https://github.com/googlefonts/ufo2ft/issues/588
See also https://github.com/googlefonts/ufo2ft/pull/811#discussion_r1461667058
This commit is contained in:
Khaled Hosny 2024-01-22 14:10:46 +02:00
parent 679a5c0c25
commit 2616ab959c
4 changed files with 7 additions and 20 deletions

View File

@ -111,10 +111,6 @@ class Lexer(object):
glyphclass = text[start + 1 : self.pos_] glyphclass = text[start + 1 : self.pos_]
if len(glyphclass) < 1: if len(glyphclass) < 1:
raise FeatureLibError("Expected glyph class name", location) raise FeatureLibError("Expected glyph class name", location)
if len(glyphclass) > 63:
raise FeatureLibError(
"Glyph class names must not be longer than 63 characters", location
)
if not Lexer.RE_GLYPHCLASS.match(glyphclass): if not Lexer.RE_GLYPHCLASS.match(glyphclass):
raise FeatureLibError( raise FeatureLibError(
"Glyph class names must consist of letters, digits, " "Glyph class names must consist of letters, digits, "

View File

@ -2071,13 +2071,7 @@ class Parser(object):
def expect_glyph_(self): def expect_glyph_(self):
self.advance_lexer_() self.advance_lexer_()
if self.cur_token_type_ is Lexer.NAME: if self.cur_token_type_ is Lexer.NAME:
self.cur_token_ = self.cur_token_.lstrip("\\") return self.cur_token_.lstrip("\\")
if len(self.cur_token_) > 63:
raise FeatureLibError(
"Glyph names must not be longer than 63 characters",
self.cur_token_location_,
)
return self.cur_token_
elif self.cur_token_type_ is Lexer.CID: elif self.cur_token_type_ is Lexer.CID:
return "cid%05d" % self.cur_token_ return "cid%05d" % self.cur_token_
raise FeatureLibError("Expected a glyph name or CID", self.cur_token_location_) raise FeatureLibError("Expected a glyph name or CID", self.cur_token_location_)

View File

@ -41,9 +41,7 @@ class LexerTest(unittest.TestCase):
self.assertEqual(lex("@Vowel-sc"), [(Lexer.GLYPHCLASS, "Vowel-sc")]) self.assertEqual(lex("@Vowel-sc"), [(Lexer.GLYPHCLASS, "Vowel-sc")])
self.assertRaisesRegex(FeatureLibError, "Expected glyph class", lex, "@(a)") self.assertRaisesRegex(FeatureLibError, "Expected glyph class", lex, "@(a)")
self.assertRaisesRegex(FeatureLibError, "Expected glyph class", lex, "@ A") self.assertRaisesRegex(FeatureLibError, "Expected glyph class", lex, "@ A")
self.assertRaisesRegex( self.assertEqual(lex("@" + ("A" * 600)), [(Lexer.GLYPHCLASS, "A" * 600)])
FeatureLibError, "not be longer than 63 characters", lex, "@" + ("A" * 64)
)
self.assertRaisesRegex( self.assertRaisesRegex(
FeatureLibError, "Glyph class names must consist of", lex, "@Ab:c" FeatureLibError, "Glyph class names must consist of", lex, "@Ab:c"
) )

View File

@ -54,6 +54,7 @@ GLYPHNAMES = (
""" """
).split() ).split()
+ ["foo.%d" % i for i in range(1, 200)] + ["foo.%d" % i for i in range(1, 200)]
+ ["G" * 600]
) )
@ -327,12 +328,10 @@ class ParserTest(unittest.TestCase):
self.assertEqual(gc.glyphSet(), ("endash", "emdash", "figuredash")) self.assertEqual(gc.glyphSet(), ("endash", "emdash", "figuredash"))
def test_glyphclass_glyphNameTooLong(self): def test_glyphclass_glyphNameTooLong(self):
self.assertRaisesRegex( gname = "G" * 600
FeatureLibError, [gc] = self.parse(f"@GlyphClass = [{gname}];").statements
"must not be longer than 63 characters", self.assertEqual(gc.name, "GlyphClass")
self.parse, self.assertEqual(gc.glyphSet(), (gname,))
"@GlyphClass = [%s];" % ("G" * 64),
)
def test_glyphclass_bad(self): def test_glyphclass_bad(self):
self.assertRaisesRegex( self.assertRaisesRegex(