Fix regex for list of points splitting: Expect at least one whitespace character or comma between coords.

The previous regex would have allowed zero length matches and therefore could have split the string after every character - luckily this was not (yet) correctly implemented in Python. Since Python 3.5 a warning is raised informing of this problem. Future versions will correctly split also at zero length matches.

See also note on https://docs.python.org/3/library/re.html#re.split
This commit is contained in:
Eduard Braun 2015-12-06 22:53:03 +01:00
parent c54c5e5d7e
commit 2293e1bd4a

View file

@ -2123,7 +2123,7 @@ def parseListOfPoints(s):
# coordinate-pair = coordinate comma-or-wsp coordinate # coordinate-pair = coordinate comma-or-wsp coordinate
# coordinate = sign? integer # coordinate = sign? integer
# comma-wsp: (wsp+ comma? wsp*) | (comma wsp*) # comma-wsp: (wsp+ comma? wsp*) | (comma wsp*)
ws_nums = re.split(r"\s*,?\s*", s.strip()) ws_nums = re.split(r"\s*[\s,]\s*", s.strip())
nums = [] nums = []
# also, if 100-100 is found, split it into two also # also, if 100-100 is found, split it into two also