diff --git a/Lib/fontTools/svgLib/path/parser.py b/Lib/fontTools/svgLib/path/parser.py index 1fcf8998c..b3218c8a7 100644 --- a/Lib/fontTools/svgLib/path/parser.py +++ b/Lib/fontTools/svgLib/path/parser.py @@ -16,10 +16,13 @@ ARC_COMMANDS = set("Aa") UPPERCASE = set('MZLHVCSQTA') COMMAND_RE = re.compile("([MmZzLlHhVvCcSsQqTtAa])") + +# https://www.w3.org/TR/css-syntax-3/#number-token-diagram +# but -6.e-5 will be tokenized as "-6" then "-5" and confuse parsing FLOAT_RE = re.compile( r"[-+]?" # optional sign r"(?:" - r"(?:0|[1-9][0-9]*)(?:\.[0-9]+(?:[eE][-+]?[0-9]+)?)?" # int/float + r"(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][-+]?[0-9]+)?" # int/float r"|" r"(?:\.[0-9]+(?:[eE][-+]?[0-9]+)?)" # float with leading dot (e.g. '.42') r")" diff --git a/Tests/svgLib/path/parser_test.py b/Tests/svgLib/path/parser_test.py index b533dd8e8..1bcd30dd5 100644 --- a/Tests/svgLib/path/parser_test.py +++ b/Tests/svgLib/path/parser_test.py @@ -280,6 +280,15 @@ def test_exponents(): assert pen.value == expected + pen = RecordingPen() + parse_path("M-3e38 3E+38L-3E-38,3e-38", pen) + expected = [ + ("moveTo", ((-3e+38, 3e+38),)), + ("lineTo", ((-3e-38, 3e-38),)), + ("endPath", ()), + ] + + assert pen.value == expected def test_invalid_implicit_command(): with pytest.raises(ValueError) as exc_info: