Commit 3d91345e authored by catch's avatar catch

Issue #2678620 by stBorchert: HandlerBase::breakString does not work with decimal values

parent cd068ef4
......@@ -712,12 +712,12 @@ public static function breakString($str, $force_int = FALSE) {
// Determine if the string has 'or' operators (plus signs) or 'and'
// operators (commas) and split the string accordingly.
if (preg_match('/^([\w0-9-_]+[+ ]+)+[\w0-9-_]+$/u', $str)) {
if (preg_match('/^([\w0-9-_\.]+[+ ]+)+[\w0-9-_\.]+$/u', $str)) {
// The '+' character in a query string may be parsed as ' '.
$operator = 'or';
$value = preg_split('/[+ ]/', $str);
}
elseif (preg_match('/^([\w0-9-_]+[, ]+)*[\w0-9-_]+$/u', $str)) {
elseif (preg_match('/^([\w0-9-_\.]+[, ]+)*[\w0-9-_\.]+$/u', $str)) {
$operator = 'and';
$value = explode(',', $str);
}
......
......@@ -67,7 +67,7 @@ function title() {
}
if (!empty($this->options['break_phrase'])) {
$break = static::breakString($this->argument, TRUE);
$break = static::breakString($this->argument, FALSE);
$this->value = $break->value;
$this->operator = $break->operator;
}
......@@ -100,7 +100,7 @@ public function query($group_by = FALSE) {
$this->ensureMyTable();
if (!empty($this->options['break_phrase'])) {
$break = static::breakString($this->argument, TRUE);
$break = static::breakString($this->argument, FALSE);
$this->value = $break->value;
$this->operator = $break->operator;
}
......
......@@ -162,6 +162,37 @@ public function testBreakString() {
$handlerBase = HandlerBase::breakString("$s1+$n2+$n3", TRUE);
$this->assertEqualValue(array((int) $s1, $n2, $n3), $handlerBase);
$this->assertEqual('or', $handlerBase->operator);
// Generate three random decimals which can be used below;
$d1 = rand(0, 10) / 10;
$d2 = rand(0, 10) / 10;
$d3 = rand(0, 10) / 10;
// Test "or"s.
$handlerBase = HandlerBase::breakString("$s1 $d1+$d2");
$this->assertEqualValue(array($s1, $d1, $d2), $handlerBase);
$this->assertEqual('or', $handlerBase->operator);
$handlerBase = HandlerBase::breakString("$s1+$d1+$d3");
$this->assertEqualValue(array($s1, $d1, $d3), $handlerBase);
$this->assertEqual('or', $handlerBase->operator);
$handlerBase = HandlerBase::breakString("$s1 $d2 $d3");
$this->assertEqualValue(array($s1, $d2, $d3), $handlerBase);
$this->assertEqual('or', $handlerBase->operator);
$handlerBase = HandlerBase::breakString("$s1 $d2++$d3");
$this->assertEqualValue(array($s1, $d2, $d3), $handlerBase);
$this->assertEqual('or', $handlerBase->operator);
// Test "and"s.
$handlerBase = HandlerBase::breakString("$s1,$d2,$d3");
$this->assertEqualValue(array($s1, $d2, $d3), $handlerBase);
$this->assertEqual('and', $handlerBase->operator);
$handlerBase = HandlerBase::breakString("$s1,,$d2,$d3");
$this->assertEqualValue(array($s1, $d2, $d3), $handlerBase);
$this->assertEqual('and', $handlerBase->operator);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment