[interchange-bugs] [rt.icdevgroup.org #350] SystemTag/assign.coretag parsing an int

Peter peter at pajamian.dhs.org
Mon Mar 19 23:12:48 UTC 2012


On 20/03/12 04:56, Anonymous via RT wrote:
> interchange/code/SystemTag/assign.coretag tries to detect illegal
> assignments of non-numbers to numeric database fields.  The
> validation is wrong, resulting in many "Attempted assign of
> non-numeric" warnings.
> 
> A better check would be:
> 
> -   if($value =~ /^-?\d+\.?\d*$/ )
> +   if($value =~ m/ ^[+-]?[0-9]+$ | ^[+-]?[0-9]*\.[0-9]+$ /x ) {
> 
> Mind you:  \d  ~=  [0-9]
> 
> By the way: this fix broke quite some code in my instance.  Handle
> with care!

Breaking lots of existing code like this simply won't work.  I think
it's a better idea to just try to "fix" any numbers that pass our old
test but still aren't real numbers.  The easy way to do this is like this:

                if($value =~ /^-?\d+\.?\d*$/) {
			no warnings 'numeric';
			$value += 0;
                        $Vend::Session->{assigned}{$_} = $value;
                }

...then we don't break existing code and we get rid of the warnings.

...of course, the warnings are indications of bad numerics to begin
with, so maybe we should still warn about them which means that either
we just leave the code as-is (them people get warnings to fix their
catalogs without actually breaking them), or change it to:

                if($value =~ /^-?\d+\.?\d*$/) {
			use warnings;
			$value += 0;
                        $Vend::Session->{assigned}{$_} = $value;
                }

...Then the warning will always come at the same place and only once.


Peter



More information about the interchange-bugs mailing list