Bug Report #4686

Valid::range() returns false for value 0

Added by Michal Musial almost 2 years ago. Updated over 1 year ago.

Status:ClosedStart date:01/13/2013
Priority:NormalDue date:
Assignee:Lorenzo Pisani% Done:

0%

Category:Core
Target version:3.3.1
Resolution: Points:1

Description

It seems that the following validation methods don't return TRUE when the value is 0.

Example:

$array = array(
    'var1'  => 0,
    'var2'  => 0,
    'var3'  => 1,
    'var4'  => 1,
);

$validation = Validation::factory($array)
    ->rule('var1', 'not_empty')
    ->rule('var1', 'range', array(':value', 0, 10));
var_dump($validation->check());

$validation = Validation::factory($array)
    ->rule('var2', 'not_empty')
    ->rule('var2', 'in_array', array(':value', range(0, 10)));
var_dump($validation->check());

$validation = Validation::factory($array)
    ->rule('var3', 'not_empty')
    ->rule('var3', 'range', array(':value', 0, 10));
var_dump($validation->check());

$validation = Validation::factory($array)
    ->rule('var4', 'not_empty')
    ->rule('var4', 'in_array', array(':value', range(0, 10)));
var_dump($validation->check());

The above will output:

bool(false)
bool(true)
bool(true)
bool(true)

Related issues

Duplicates Kohana v3.x - Bug Report #4672: Valid::range bug (min/max were excluded) Closed 12/06/2012

History

#1 Updated by Alexey Zagaichuk almost 2 years ago

From Kohana 3.2 sources:

public static function range($number, $min, $max)
{ 
    return ($number >= $min AND $number <= $max);
}

From Kohana 3.3 sources:

public static function range($number, $min, $max, $step = NULL)
{
    if ($number <= $min OR $number >= $max)
    {
        // Number is outside of range
        return FALSE;
    }
    ...
}

So conditions >= and <= were bogus reverted to <= and >= instead of < and >.

#2 Updated by Torleif Berger almost 2 years ago

Yeah, it has become exclusive rather than inclusive. Not good :)

#3 Updated by Lorenzo Pisani almost 2 years ago

  • Status changed from New to Assigned
  • Assignee set to Lorenzo Pisani
  • Target version set to 3.3.1

#4 Updated by Daniel Macedo almost 2 years ago

Hi,

This issue is a duplicate of #4672, which has my pull request to fix it (including the necessary tests)

Jeremy already updated the ticket back in early December but hasn't merged the pull request yet.

#5 Updated by Anonymous over 1 year ago

  • Status changed from Assigned to Closed

Applied in changeset commit:4b635e5bf07ef4d78ab5dc3172b8d4783aa071a1.

Also available in: Atom PDF