]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 523977: Make Bugzilla::Object->check send the trimmed value to new(), and also...
authormkanat%bugzilla.org <>
Sat, 24 Oct 2009 05:26:35 +0000 (05:26 +0000)
committermkanat%bugzilla.org <>
Sat, 24 Oct 2009 05:26:35 +0000 (05:26 +0000)
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=LpSolit

Bugzilla/Object.pm
Bugzilla/Util.pm

index 456888b381aa16bedd54d88bf39d19113e4566e4..b04593f8915bd9ae5ac4b98f2c1adb38ed16cf55 100644 (file)
@@ -117,10 +117,17 @@ sub check {
     if (!ref $param) {
         $param = { name => $param };
     }
+
     # Don't allow empty names or ids.
-    my $check_param = exists $param->{id} ? $param->{id} : $param->{name};
-    $check_param = trim($check_param);
-    $check_param || ThrowUserError('object_not_specified', { class => $class });
+    my $check_param = exists $param->{id} ? 'id' : 'name';
+    $param->{$check_param} = trim($param->{$check_param});
+    # If somebody passes us "0", we want to throw an error like
+    # "there is no X with the name 0". This is true even for ids. So here,
+    # we only check if the parameter is undefined or empty.
+    if (!defined $param->{$check_param} or $param->{$check_param} eq '') {
+        ThrowUserError('object_not_specified', { class => $class });
+    }
+
     my $obj = $class->new($param);
     if (!$obj) {
         # We don't want to override the normal template "user" object if
index 513e0285734e4c72fff353ec09818edeee459a19..21588417ccea8f7ad648a389ffe41f27e917c8d0 100644 (file)
@@ -68,17 +68,14 @@ sub trick_taint {
 
 sub detaint_natural {
     my $match = $_[0] =~ /^(\d+)$/;
-    $_[0] = $match ? $1 : undef;
+    $_[0] = $match ? int($1) : undef;
     return (defined($_[0]));
 }
 
 sub detaint_signed {
     my $match = $_[0] =~ /^([-+]?\d+)$/;
-    $_[0] = $match ? $1 : undef;
-    # Remove any leading plus sign.
-    if (defined($_[0]) && $_[0] =~ /^\+(\d+)$/) {
-        $_[0] = $1;
-    }
+    # The "int()" call removes any leading plus sign.
+    $_[0] = $match ? int($1) : undef;
     return (defined($_[0]));
 }