Skip to content

Commit 1582cf2

Browse files
committed
Fixed critical recursion bug
1 parent 39b9481 commit 1582cf2

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

datetimeparser/parsermethods.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,8 @@ class AbsolutePrepositionParser:
631631
"before"
632632
)
633633

634+
MAX_RECURSION_DEPTH = 13
635+
634636
def _split_data(self, string: str) -> Optional[Tuple[dict, dict, dict]]:
635637
"""
636638
Splits the data into 3 parts
@@ -661,8 +663,10 @@ def _split_data(self, string: str) -> Optional[Tuple[dict, dict, dict]]:
661663
absolute = string[char_count:]
662664

663665
# There may be more prepositions in the absolute part so we try it again via recursion
664-
if self._split_data(absolute) is not None:
665-
absolute = self._split_data(absolute)
666+
recursion_result = self._split_data(absolute)
667+
668+
if recursion_result is not None:
669+
absolute = recursion_result
666670

667671
return {'type': 'relative', 'data': relative}, {'type': 'keyword', 'data': word}, {'type': 'absolute', 'data': absolute}
668672

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
long_description_content_type="text/markdown",
1111
long_description=long_description,
1212
packages=['datetimeparser'],
13-
version='0.3a', # version number: https://peps.python.org/pep-0440/
13+
version='0.4rc', # version number: https://peps.python.org/pep-0440/
1414
license='MIT',
1515
description='A parser library built for parsing the english language into datetime objects.',
1616
author='Ari24',

0 commit comments

Comments
 (0)