diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 362b9d8..e35f315 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,6 +47,7 @@ jobs: run: perl -V - name: install test deps using cpm uses: perl-actions/install-with-cpm@v1 + continue-on-error: true with: sudo: false global: false diff --git a/lib/Date/Parse.pm b/lib/Date/Parse.pm index 640f9bd..7985022 100644 --- a/lib/Date/Parse.pm +++ b/lib/Date/Parse.pm @@ -122,7 +122,7 @@ sub { # default C++ boost timestamp is effectively %Y-%b-%d %H:%M:%S.%f # details: https://svn.boost.org/trac/boost/ticket/8839 - if ($dtstr =~ s/\s(\d{4})([-:]?)(\w{3,})\2(\d\d?)(?:[-Tt ](\d\d?)(?:([-:]?)(\d\d?)(?:\6(\d\d?)(?:[.,](\d+))?)?)?)?(?=\D)/ /) { + if ($dtstr =~ s/\s(\d{4})([-:]?)($monpat)\2(\d\d?)(?:[-Tt ](\d\d?)(?:([-:]?)(\d\d?)(?:\6(\d\d?)(?:[.,](\d+))?)?)?)?(?=\D)/ /oi) { ($year,$month,$day,$hh,$mm,$ss,$frac) = ($1,$month{$3},$4,$5,$7,$8,$9); } diff --git a/t/cpanrt-parse.t b/t/cpanrt-parse.t index 46f6689..561166a 100644 --- a/t/cpanrt-parse.t +++ b/t/cpanrt-parse.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 26; +use Test::More tests => 36; use Date::Parse qw(strptime str2time); # RT#48164: Date::Parse unable to set seconds correctly @@ -122,3 +122,34 @@ use Date::Parse qw(strptime str2time); ok(!defined($t), "RT#125949: str2time('199001') returns undef for ambiguous 6-digit input"); } + +# Boost format (%Y-%b-%d) should only match valid month names, not arbitrary words. +# Before the fix, "2024-abc-15" silently parsed using the current month as default. +{ + ok(!defined(str2time("2024-abc-15")), + "boost format: non-month word 'abc' is rejected"); + ok(!defined(str2time("2024-foo-01")), + "boost format: non-month word 'foo' is rejected"); + + # Valid boost-format dates must still parse correctly + my $t = str2time("2024-Jan-15 12:00:00 UTC"); + ok(defined($t), "boost format: '2024-Jan-15' is accepted"); + my @g = gmtime($t); + is($g[3], 15, "boost format: '2024-Jan-15' gives day=15"); + + # Case-insensitive month matching + my $t_uc = str2time("2024-JAN-15 12:00:00 UTC"); + ok(defined($t_uc), "boost format: '2024-JAN-15' (uppercase) is accepted"); + my @g_uc = gmtime($t_uc); + is($g_uc[3], 15, "boost format: '2024-JAN-15' gives day=15"); + + my $t_lc = str2time("2024-jan-15 12:00:00 UTC"); + ok(defined($t_lc), "boost format: '2024-jan-15' (lowercase) is accepted"); + my @g_lc = gmtime($t_lc); + is($g_lc[3], 15, "boost format: '2024-jan-15' gives day=15"); + + my $t_mc = str2time("2024-JaN-15 12:00:00 UTC"); + ok(defined($t_mc), "boost format: '2024-JaN-15' (mixed case) is accepted"); + my @g_mc = gmtime($t_mc); + is($g_mc[3], 15, "boost format: '2024-JaN-15' gives day=15"); +}