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

Require Western Arabic (ASCII) numerals for max_rows #1

Merged
merged 1 commit into from
Feb 15, 2013
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
2 changes: 1 addition & 1 deletion lib/Text/CSV/Hashify.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ sub new {
$data{key} = delete $args->{key}; $data{key} = delete $args->{key};


if (defined($args->{max_rows})) { if (defined($args->{max_rows})) {
if ($args->{max_rows} !~ m/^\d+$/) { if ($args->{max_rows} !~ m/^[0-9]+$/) {
croak "'max_rows' option, if defined, must be numeric"; croak "'max_rows' option, if defined, must be numeric";
} }
else { else {
Expand Down
35 changes: 34 additions & 1 deletion t/001-new.t
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# t/001-new.t - check constructor # t/001-new.t - check constructor
use strict; use strict;
use warnings; use warnings;
use utf8;
use Carp; use Carp;
use Scalar::Util qw( reftype looks_like_number ); use Scalar::Util qw( reftype looks_like_number );
use Test::More tests => 24; use Test::More tests => 26;
use lib ('./lib'); use lib ('./lib');
use Text::CSV::Hashify; use Text::CSV::Hashify;


Expand Down Expand Up @@ -112,6 +113,38 @@ my ($obj, $source, $key, $k, $limit);
"'max_rows' option to new() must be numeric"); "'max_rows' option to new() must be numeric");
} }


{
$source = "./t/data/names.csv";
$key = 'id';
$limit = '٤٠'; # 40 in Eastern Arabic numerals
local $@;
eval {
$obj = Text::CSV::Hashify->new( {
file => $source,
key => $key,
max_rows => $limit,
} );
};
like($@, qr/^'max_rows' option, if defined, must be numeric/,
"'max_rows' option to new() must be in Western Arabic numerals");
}

{
$source = "./t/data/names.csv";
$key = 'id';
$limit = '2٧'; # Western Arabic 2 followed by Eastern Arabic 7
local $@;
eval {
$obj = Text::CSV::Hashify->new( {
file => $source,
key => $key,
max_rows => $limit,
} );
};
like($@, qr/^'max_rows' option, if defined, must be numeric/,
"'max_rows' option to new() must be only in Western Arabic numerals");
}

{ {
$source = "./t/data/dupe_field_names.csv"; $source = "./t/data/dupe_field_names.csv";
$key = 'id'; $key = 'id';
Expand Down