Merge pull request #2611 from tshinnic/svglib_parser_real_number_format

Handle one more valid real number format in svgLib parse_path()
This commit is contained in:
Cosimo Lupo 2022-05-04 08:27:24 +01:00 committed by GitHub
commit b488d10768
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -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")"

View File

@ -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: