Skip to content

Commit 2ca3052

Browse files
committed
Strings containing only separator tokens must not consider the tokens set as valid
1 parent a08cecc commit 2ca3052

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

dateparser/languages/dictionary.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ def are_tokens_valid(self, tokens):
103103
104104
:return: True if tokens are valid, False otherwise.
105105
"""
106+
has_only_keep_tokens = not set(tokens) - set(ALWAYS_KEEP_TOKENS)
107+
if has_only_keep_tokens:
108+
return False
109+
106110
match_relative_regex = self._get_match_relative_regex_cache()
107111
for token in tokens:
108112
if any([match_relative_regex.match(token),

tests/test_date_parser.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,20 @@ def test_if_settings_provided_date_order_is_retained(
703703
self.then_date_was_parsed_by_date_parser()
704704
self.then_date_obj_exactly_is(expected)
705705

706+
@parameterized.expand([
707+
param('::', None),
708+
param('..', None),
709+
param(' ', None),
710+
param('--', None),
711+
param('//', None),
712+
param('++', None),
713+
])
714+
def test_parsing_strings_containing_only_separator_tokens(self, date_string, expected):
715+
self.given_parser()
716+
self.when_date_is_parsed(date_string)
717+
self.then_period_is('day')
718+
self.then_date_obj_exactly_is(expected)
719+
706720
def given_local_tz_offset(self, offset):
707721
self.add_patch(
708722
patch.object(dateparser.timezone_parser,

0 commit comments

Comments
 (0)