FIX: prevents time sniffer to match a date starting with the year

This commit is contained in:
jjaffeux 2020-03-27 19:36:01 +01:00
parent f7c2903096
commit 4677307e74
2 changed files with 6 additions and 1 deletions

View File

@ -312,7 +312,7 @@ class TimeSniffer
end
DATE_SEPARATOR = /[-\/]/
DATE_REGEX = /(\d{1,2})#{DATE_SEPARATOR}(\d{1,2})#{DATE_SEPARATOR}(\d{2,4})/
DATE_REGEX = /((?:^|\s)\d{1,2})#{DATE_SEPARATOR}(\d{1,2})#{DATE_SEPARATOR}(\d{2,4})/
matcher(:date, DATE_REGEX) do |m|
Parser.new(input, @context).parse_range

View File

@ -208,4 +208,9 @@ describe TimeSniffer do
it "should not find a time in random numbers and an emoji" do
expect_parsed_as_nil("15😊00")
end
it "shouldnt match a date starting with the year" do
expect_parsed_as_nil("2020-03-27")
expect_parsed_as_nil("foo 2020-03-27")
end
end