Bugzilla – Attachment 23477 Details for
Bug 10861
Add a check on cardnumber length
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10861: Reintroduced the cardnumber length check (client side)
Bug-10861-Reintroduced-the-cardnumber-length-check.patch (text/plain), 4.39 KB, created by
Jonathan Druart
on 2013-12-12 09:45:52 UTC
(
hide
)
Description:
Bug 10861: Reintroduced the cardnumber length check (client side)
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2013-12-12 09:45:52 UTC
Size:
4.39 KB
patch
obsolete
>From e4c83341065c13ed1e7f90b249f5ed46e6736132 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Thu, 12 Dec 2013 10:42:46 +0100 >Subject: [PATCH] Bug 10861: Reintroduced the cardnumber length check (client > side) > >Previous patches has removed the pattern attribute of the input, it was >not needed. This patch reintroduces it. It will only work for new >browser version. > >Moreover, it manages with the ',XX' format (see UT). >--- > C4/Members.pm | 12 +++++++----- > .../prog/en/modules/members/memberentrygen.tt | 8 +++++++- > t/Members/cardnumber.t | 13 +++++++++++-- > 3 files changed, 25 insertions(+), 8 deletions(-) > >diff --git a/C4/Members.pm b/C4/Members.pm >index b26ed63..9cfb72d 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -1352,16 +1352,18 @@ sub checkcardnumber { > } > > sub get_cardnumber_length { >- my ( $min, $max ) = ( 0, 16 ); >+ my ( $min, $max ) = ( 1, 16 ); # borrowers.cardnumber is a varchar(16) > if ( my $cardnumber_length = C4::Context->preference('CardnumberLength') ) { > # Is integer and length match > if ( $cardnumber_length =~ m|^\d+$| ) { >- $min = $max = $cardnumber_length; >+ $min = $max = $cardnumber_length >+ if $cardnumber_length >= $min >+ and $cardnumber_length <= $max; > } > # Else assuming it is a range >- elsif ( $cardnumber_length =~ m|(\d+),(\d*)| ) { >- $min = $1; >- $max = $2 || 16; # borrowers.cardnumber is a varchar(16) >+ elsif ( $cardnumber_length =~ m|(\d*),(\d*)| ) { >+ $min = $1 if $1 and $min < $1; >+ $max = $2 if $2 and $max > $2; > } > > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt >index cda4e9c..1769886 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt >@@ -863,7 +863,13 @@ > <label for="cardnumber"> > [% END %] > Card number: </label> >- <input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber %]" /> >+ [% IF minlength_cardnumber == maxlength_cardnumber %] >+ <input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber %]" pattern=".{[% minlength_cardnumber %]}" title="Exactly [% minlength_cardnumber %] characters" /> >+ [% ELSIF minlength_cardnumber && maxlength_cardnumber %] >+ <input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber %]" pattern=".{[% minlength_cardnumber %],[% maxlength_cardnumber %]}" title="between [% minlength_cardnumber %] and [% maxlength_cardnumber %] characters" /> >+ [% ELSE %] >+ <input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber %]" /> >+ [% END %] > [% IF ( mandatorycardnumber ) %]<span class="required">Required</span>[% END %] > </li> > [% END %] >diff --git a/t/Members/cardnumber.t b/t/Members/cardnumber.t >index 2fe606c..8132c93 100644 >--- a/t/Members/cardnumber.t >+++ b/t/Members/cardnumber.t >@@ -1,7 +1,7 @@ > #!/usr/bin/env perl > > use Modern::Perl; >-use Test::More tests =>18; >+use Test::More tests => 22; > > use Test::MockModule; > use DBD::Mock; >@@ -61,8 +61,17 @@ is( C4::Members::checkcardnumber( q{1234567} ), 2, "1234567 is shorter than $pre > $dbh->{mock_add_resultset} = $rs; > is( C4::Members::checkcardnumber( q{1234567890123456} ), 0, "1234567890123456 matches $pref"); > $dbh->{mock_add_resultset} = $rs; >-is( C4::Members::checkcardnumber( q{1234567890} ), 0, "12345678 matches $pref"); >+is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 matches $pref"); > >+$pref = q|,8|; # max 8 chars >+set_pref( $module_context, $pref ); >+is_deeply( [ C4::Members::get_cardnumber_length() ], [ 1, 8 ], ',8 => min=1 and max=8'); >+$dbh->{mock_add_resultset} = $rs; >+is( C4::Members::checkcardnumber( q{1234567} ), 0, "1234567 matches $pref"); >+$dbh->{mock_add_resultset} = $rs; >+is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is longer than $pref"); >+$dbh->{mock_add_resultset} = $rs; >+is( C4::Members::checkcardnumber( q{1234567890} ), 2, "1234567890 is longer than $pref"); > > > sub set_pref { >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 10861
:
20950
|
21196
|
21586
|
23387
|
23388
|
23439
|
23476
|
23477
|
23563
|
23564
|
23565
|
23732
|
23733
|
23734
|
23735
|
23736