summaryrefslogtreecommitdiff
path: root/dateutil/parser
diff options
context:
space:
mode:
authorMario Corchero <mcorcherojim@bloomberg.net>2021-05-16 22:35:11 +0200
committerMario Corchero <mcorcherojim@bloomberg.net>2021-05-19 21:00:32 +0200
commit34906dcd4112197c8f6386f799c10b8a34cb248f (patch)
tree587de2ccd383150ceed35744a1b81c689d4df886 /dateutil/parser
parent9edac50ef325156e06356304087feeb20e4b7d4a (diff)
downloaddateutil-git-34906dcd4112197c8f6386f799c10b8a34cb248f.tar.gz
isoparse: Fail with inconsistent time separators
Fail when separators are used inconsistently to split the time porting of a string. Even if more restrictive, we have warned that we were going to fail on invalid cases of ISO formatted strings. This will prevent invalid iso formatted strings from being unexpectedly parsed.
Diffstat (limited to 'dateutil/parser')
-rw-r--r--dateutil/parser/isoparser.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/dateutil/parser/isoparser.py b/dateutil/parser/isoparser.py
index 48f86a3..64a54ff 100644
--- a/dateutil/parser/isoparser.py
+++ b/dateutil/parser/isoparser.py
@@ -336,7 +336,7 @@ class isoparser(object):
if len(timestr) < 2:
raise ValueError('ISO time too short')
- has_sep = len_str >= 3 and timestr[2:3] == self._TIME_SEP
+ has_sep = False
while pos < len_str and comp < 5:
comp += 1
@@ -347,13 +347,18 @@ class isoparser(object):
pos = len_str
break
+ if comp == 1 and timestr[pos:pos+1] == self._TIME_SEP:
+ has_sep = True
+ pos += 1
+ elif comp == 2 and has_sep:
+ if timestr[pos:pos+1] != self._TIME_SEP:
+ raise ValueError('Inconsistent use of colon separator')
+ pos += 1
+
if comp < 3:
# Hour, minute, second
components[comp] = int(timestr[pos:pos + 2])
pos += 2
- if (has_sep and pos < len_str and
- timestr[pos:pos + 1] == self._TIME_SEP):
- pos += 1
if comp == 3:
# Fraction of a second