Skip Menu |

This queue is for tickets about the HTML-FormFu CPAN distribution.

Report information
The Basics
Id: 38899
Status: resolved
Priority: 0/
Queue: HTML-FormFu

People
Owner: Nobody in particular
Requestors: rod.taylor [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.03003
Fixed in: (no value)



Subject: Filter Non-Numeric strips decimal
The NonNumeric filter strips the decimal so "2.55" becomes "255". I had a field which was populated to include 2 decimal places and submit would shift the value 2 digits left. Quite annoying. I think Least Surprise is to keep decimal places. Below patch causes it to keep the decimal place. *** NonNumeric.pm.orig Mon Sep 1 10:14:18 2008 --- NonNumeric.pm Mon Sep 1 10:14:31 2008 *************** *** 3,9 **** use strict; use base 'HTML::FormFu::Filter::Regex'; ! sub match {qr/\D+/} 1; --- 3,9 ---- use strict; use base 'HTML::FormFu::Filter::Regex'; ! sub match {qr/[^\d.]/} 1;
Subject: Re: [rt.cpan.org #38899] Filter Non-Numeric strips decimal
Date: Mon, 1 Sep 2008 16:25:49 +0200
To: "bug-HTML-FormFu [...] rt.cpan.org" <bug-HTML-FormFu [...] rt.cpan.org>
From: Andreas Marienborg <omega [...] palle.net>
A test would be cool :) also, how does it work with locales? Thanks for the bug and interest :) Andreas On 1. sep.. 2008, at 16.19, "Rod Taylor via RT" <bug-HTML-FormFu@rt.cpan.org Show quoted text
> wrote:
Show quoted text
> Mon Sep 01 10:19:05 2008: Request 38899 was acted upon. > Transaction: Ticket created by rtaylor > Queue: HTML-FormFu > Subject: Filter Non-Numeric strips decimal > Broken in: 0.03003 > Severity: Normal > Owner: Nobody > Requestors: rod.taylor@gmail.com > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=38899 > > > > The NonNumeric filter strips the decimal so "2.55" becomes "255". > > I had a field which was populated to include 2 decimal places and > submit > would shift the value 2 digits left. Quite annoying. I think Least > Surprise is to keep decimal places. > > > Below patch causes it to keep the decimal place. > > *** NonNumeric.pm.orig Mon Sep 1 10:14:18 2008 > --- NonNumeric.pm Mon Sep 1 10:14:31 2008 > *************** > *** 3,9 **** > use strict; > use base 'HTML::FormFu::Filter::Regex'; > > ! sub match {qr/\D+/} > > 1; > > --- 3,9 ---- > use strict; > use base 'HTML::FormFu::Filter::Regex'; > > ! sub match {qr/[^\d.]/} > > 1; >
From: rod.taylor [...] gmail.com
It doesn't look for the thousands/decimal separators for the locale. Rightfully the locale should come from the webbrowser but I don't have a clue how to obtain that kind of information. Here is a test for the decimal place as "." character only. *** ./t/filters/nonnumeric.t.orig Thu May 29 05:23:02 2008 --- ./t/filters/nonnumeric.t Mon Sep 1 10:36:50 2008 *************** *** 1,20 **** use strict; use warnings; ! use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->filter('NonNumeric'); my $original_foo = " 0123-4567 (8a9)"; my $filtered_foo = "0123456789"; ! $form->process( { foo => $original_foo, } ); # foo is filtered is( $form->param('foo'), $filtered_foo, 'foo filtered' ); is( $form->params->{foo}, $filtered_foo, 'foo filtered' ); --- 1,26 ---- use strict; use warnings; ! use Test::More tests => 3; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->filter('NonNumeric'); + $form->element('Text')->name('bar')->filter('NonNumeric'); my $original_foo = " 0123-4567 (8a9)"; my $filtered_foo = "0123456789"; ! my $original_bar = '2.54%'; ! my $filtered_bar = '2.54'; ! ! $form->process( { foo => $original_foo, bar => $original_bar} ); # foo is filtered is( $form->param('foo'), $filtered_foo, 'foo filtered' ); is( $form->params->{foo}, $filtered_foo, 'foo filtered' ); + is( $form->param('bar'), $filtered_bar, 'bar filtered' ); + On Mon Sep 01 10:27:26 2008, ANDREMAR wrote: Show quoted text
> A test would be cool :) also, how does it work with locales? > > Thanks for the bug and interest :) > > Andreas > > On 1. sep.. 2008, at 16.19, "Rod Taylor via RT" <bug-HTML- > FormFu@rt.cpan.org
> > wrote:
>
> > Mon Sep 01 10:19:05 2008: Request 38899 was acted upon. > > Transaction: Ticket created by rtaylor > > Queue: HTML-FormFu > > Subject: Filter Non-Numeric strips decimal > > Broken in: 0.03003 > > Severity: Normal > > Owner: Nobody > > Requestors: rod.taylor@gmail.com > > Status: new > > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=38899 > > > > > > > The NonNumeric filter strips the decimal so "2.55" becomes "255". > > > > I had a field which was populated to include 2 decimal places and > > submit > > would shift the value 2 digits left. Quite annoying. I think Least > > Surprise is to keep decimal places. > > > > > > Below patch causes it to keep the decimal place. > > > > *** NonNumeric.pm.orig Mon Sep 1 10:14:18 2008 > > --- NonNumeric.pm Mon Sep 1 10:14:31 2008 > > *************** > > *** 3,9 **** > > use strict; > > use base 'HTML::FormFu::Filter::Regex'; > > > > ! sub match {qr/\D+/} > > > > 1; > > > > --- 3,9 ---- > > use strict; > > use base 'HTML::FormFu::Filter::Regex'; > > > > ! sub match {qr/[^\d.]/} > > > > 1; > >
On Mon Sep 01 10:19:05 2008, rtaylor wrote: Show quoted text
> The NonNumeric filter strips the decimal so "2.55" becomes "255". > > I had a field which was populated to include 2 decimal places and submit > would shift the value 2 digits left. Quite annoying. I think Least > Surprise is to keep decimal places.
This filter is to strip non-numeric "characters" - not non-number values. The patch would allow, for example: ".2.3.", which isn't really any use for anything. Also, take note that \D allows any unicode number char - not just [0-9] - this is intentional. Maybe you just need the TrimEdges filter and then the Number constraint? Carl
From: rod.taylor [...] gmail.com
I wanted a filter that would remove %, $, and thousands/millions separators but keep the decimal place intact. On Mon Sep 01 10:58:51 2008, CFRANKS wrote: Show quoted text
> On Mon Sep 01 10:19:05 2008, rtaylor wrote:
> > The NonNumeric filter strips the decimal so "2.55" becomes "255". > > > > I had a field which was populated to include 2 decimal places and submit > > would shift the value 2 digits left. Quite annoying. I think Least > > Surprise is to keep decimal places.
> > This filter is to strip non-numeric "characters" - not non-number values. > The patch would allow, for example: ".2.3.", which isn't really any use > for anything. > > Also, take note that \D allows any unicode number char - not just [0-9] > - this is intentional. > > Maybe you just need the TrimEdges filter and then the Number constraint? > > Carl
On Mon Sep 01 11:30:15 2008, rtaylor wrote: Show quoted text
> I wanted a filter that would remove %, $, and thousands/millions > separators but keep the decimal place intact.
As the NonNumeric filter inherits from the Regex filter - you can achieve this by doing this: constraint: - type: Regex match: '[^0-9.]'