Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only match ASCII digits in from_string() method. #1

Merged
merged 1 commit into from
Apr 22, 2018
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
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion lib/DateTime/Tiny.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
}
Expand Down
10 changes: 9 additions & 1 deletion t/02_main.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ BEGIN {
$^W = 1;
}

use Test::More tests => 31;
use Test::More tests => 32;
use DateTime::Tiny;
use utf8;



Expand Down Expand Up @@ -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';
}