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

Conversation

Ovid
Copy link
Contributor

@Ovid Ovid commented Oct 28, 2016

This code currently works:

my $datetime = DateTime::Tiny->from_string('୭୮୯௦-௧௨-௩௪T௫௬:௭௮:௯౦');

But it spits out warnings when you try to print it via as_string() because \d in regexes matches more than just ASCII digits. The following test program shows the problem:

use 5.10.0;
use utf8::all;
my $num_matched = 0;
for ( 1 .. 2**16 ) {
    my $char = chr($_);

    if ( $char =~ /\d/ ) {
        $num_matched++;
        say "$_ => $char";
    }
}
say "$num_matched characters matched";
#350 characters matched

The pull request substitutes [0-9] for \d in the from_string() regex (thus being compatible with older Perls) to fix this issue. There is a test to verify the expected exception.

@coveralls
Copy link

Coverage Status

Coverage increased (+7.1%) to 93.333% when pulling 14dfc00 on Ovid:master into 36a2439 on dagolden:master.

@xdg xdg merged commit 14dfc00 into dagolden:master Apr 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants