From 4f422ae415e8c9591677b97faf0776ece6d7afb8 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Tue, 20 Jan 2015 17:59:19 +0100 Subject: Don't match garbage characters at the end of time strings Addresses #15. --- src/isodate/isotime.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/isodate/isotime.py b/src/isodate/isotime.py index 151a3f9..8b4d13c 100644 --- a/src/isodate/isotime.py +++ b/src/isodate/isotime.py @@ -67,26 +67,25 @@ def build_time_regexps(): # +-hhmm # +-hh => # isotzinfo.TZ_REGEX + def add_re(regex_text): + TIME_REGEX_CACHE.append( + re.compile('\A' + regex_text + TZ_REGEX + '\Z')) # 1. complete time: # hh:mm:ss.ss ... extended format - TIME_REGEX_CACHE.append(re.compile(r"T?(?P[0-9]{2}):" - r"(?P[0-9]{2}):" - r"(?P[0-9]{2}([,.][0-9]+)?)" - + TZ_REGEX)) + add_re(r"T?(?P[0-9]{2}):" + r"(?P[0-9]{2}):" + r"(?P[0-9]{2}([,.][0-9]+)?)") # hhmmss.ss ... basic format - TIME_REGEX_CACHE.append(re.compile(r"T?(?P[0-9]{2})" - r"(?P[0-9]{2})" - r"(?P[0-9]{2}([,.][0-9]+)?)" - + TZ_REGEX)) + add_re(r"T?(?P[0-9]{2})" + r"(?P[0-9]{2})" + r"(?P[0-9]{2}([,.][0-9]+)?)") # 2. reduced accuracy: # hh:mm.mm ... extended format # hhmm.mm ... basic format - TIME_REGEX_CACHE.append(re.compile(r"T?(?P[0-9]{2}):?" - r"(?P[0-9]{2}([,.][0-9]+)?)" - + TZ_REGEX)) + add_re(r"T?(?P[0-9]{2}):?" + r"(?P[0-9]{2}([,.][0-9]+)?)") # hh.hh ... basic format - TIME_REGEX_CACHE.append(re.compile(r"T?(?P[0-9]{2}([,.][0-9]+)?)" - + TZ_REGEX)) + add_re(r"T?(?P[0-9]{2}([,.][0-9]+)?)") return TIME_REGEX_CACHE -- cgit v1.2.1