diff --git a/Changes b/Changes index 608668c..269cc9d 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,9 @@ Changes for Perl extension DateTime-Tiny {{$NEXT}} +1.07 + - Bugfix: only match ASCII digits in from_string() method. + 1.06 2016-06-23 09:43:41-04:00 America/New_York - No changes from 1.05 diff --git a/lib/DateTime/Tiny.pm b/lib/DateTime/Tiny.pm index 645244e..e793fb7 100644 --- a/lib/DateTime/Tiny.pm +++ b/lib/DateTime/Tiny.pm @@ -197,7 +197,8 @@ sub from_string { require Carp; Carp::croak("Did not provide a string to from_string"); } - unless ( $string =~ /^(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)$/ ) { + my $d = '[0-9]'; # backwards-compatible way of not matching anything but ASCII digits + unless ( $string =~ /^($d$d$d$d)-($d$d)-($d$d)T($d$d):($d$d):($d$d)$/ ) { require Carp; Carp::croak("Invalid time format (does not match ISO 8601)"); } diff --git a/t/02_main.t b/t/02_main.t index 55ac54d..03b3a41 100644 --- a/t/02_main.t +++ b/t/02_main.t @@ -8,8 +8,9 @@ BEGIN { $^W = 1; } -use Test::More tests => 31; +use Test::More tests => 32; use DateTime::Tiny; +use utf8; @@ -114,3 +115,10 @@ SCOPE: { $tiny, '->from_string ok', ); } + +SCOPE: { + eval { DateTime::Tiny->from_string('୭୮୯௦-௧௨-௩௪T௫௬:௭௮:௯౦') }; + my $error = $@; + like $error, qr/\QInvalid time format (does not match ISO 8601)/, + 'Only ASCII digits are valid in datetime strings'; +}