Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/Date/Parse.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
33 changes: 32 additions & 1 deletion t/cpanrt-parse.t
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's also add other tests for JAN, jan, JaN

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");
}
Loading