Skip to content

Commit

Permalink
Allow decimal numbers with decimal point but zero decimals (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
regebro committed Jun 11, 2022
1 parent db9931d commit d43af9f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Changelog
6.2 (unreleased)
----------------

- Nothing changed yet.
- Allow numbers with decimal point but no decimals, because other parsers do.


6.1 (2022-06-09)
Expand Down
4 changes: 2 additions & 2 deletions src/svg/path/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
UPPERCASE = set("MZLHVCSQTA")

COMMAND_RE = re.compile(r"([MmZzLlHhVvCcSsQqTtAa])")
FLOAT_RE = re.compile(rb"^[-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?")
FLOAT_RE = re.compile(rb"^[-+]?\d*\.?\d*(?:[eE][-+]?\d+)?")


class InvalidPathError(ValueError):
Expand Down Expand Up @@ -42,7 +42,7 @@ def strip_array(arg_array):

def pop_number(arg_array):
res = FLOAT_RE.search(arg_array)
if not res:
if not res or not res.group():
raise InvalidPathError(f"Expected a number, got '{arg_array}'.")
number = float(res.group())
start = res.start()
Expand Down
7 changes: 7 additions & 0 deletions src/svg/path/tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,10 @@ def test_arc_flag(self):
self.assertEqual(len(path), 15)
# It ends on a vertical line to Y 1:
self.assertEqual(path[-1].end.imag, 1)

def test_incomplete_numbers(self):
path = parse_path("M 0. .1")
self.assertEqual(path.d(), "M 0,0.1")

path = parse_path("M 0..1")
self.assertEqual(path.d(), "M 0,0.1")

0 comments on commit d43af9f

Please sign in to comment.