[feaLib] Correctly handle octal numbers

From https://www.adobe.com/devnet/opentype/afdko/topic_feature_file_syntax.html#9.e:
> Decimal numbers must begin with a non-0 digit, octal numbers with a 0
> digit, and hexadecimal numbers with a 0x prefix to numbers and
> hexadecimal letters a-f or A-F.

Fixes https://github.com/fonttools/fonttools/issues/1541
This commit is contained in:
Khaled Hosny 2019-08-17 04:40:38 +02:00
parent 6cb0a56020
commit ae239722d4
2 changed files with 4 additions and 0 deletions

View File

@ -124,6 +124,9 @@ class Lexer(object):
self.pos_ += 2
self.scan_over_(Lexer.CHAR_HEXDIGIT_)
return (Lexer.NUMBER, int(text[start:self.pos_], 16), location)
if cur_char == "0" and next_char in Lexer.CHAR_DIGIT_:
self.scan_over_(Lexer.CHAR_DIGIT_)
return (Lexer.NUMBER, int(text[start:self.pos_], 8), location)
if cur_char in Lexer.CHAR_DIGIT_:
self.scan_over_(Lexer.CHAR_DIGIT_)
if self.pos_ >= limit or text[self.pos_] != ".":

View File

@ -69,6 +69,7 @@ class LexerTest(unittest.TestCase):
[(Lexer.NUMBER, 123), (Lexer.NUMBER, -456)])
self.assertEqual(lex("0xCAFED00D"), [(Lexer.NUMBER, 0xCAFED00D)])
self.assertEqual(lex("0xcafed00d"), [(Lexer.NUMBER, 0xCAFED00D)])
self.assertEqual(lex("010"), [(Lexer.NUMBER, 0o10)])
def test_float(self):
self.assertEqual(lex("1.23 -4.5"),