Issue #1417400 by David_Rothstein | josaku: Fixed Various characters (UTF-8 characters, dashes, and symbols) cause views_break_phrase_string() not to work.

8.0.x
drothstein 2012-07-22 19:20:24 +02:00 committed by Tim Plunkett
parent d587e77168
commit 10a85c7e03
2 changed files with 35 additions and 11 deletions

View File

@ -1073,12 +1073,17 @@ function views_break_phrase_string($str, &$handler = NULL) {
return $handler;
}
if (preg_match('/^(\w+[+ ])+\w+$/', $str)) {
// The '+' character in a query string may be parsed as ' '.
// Determine if the string has 'or' operators (plus signs) or 'and' operators
// (commas) and split the string accordingly. If we have an 'and' operator,
// spaces are treated as part of the word being split, but otherwise they are
// treated the same as a plus sign.
$or_wildcard = '[^\s+,]';
$and_wildcard = '[^+,]';
if (preg_match("/^({$or_wildcard}+[+ ])+{$or_wildcard}+$/", $str)) {
$handler->operator = 'or';
$handler->value = preg_split('/[+ ]/', $str);
}
else if (preg_match('/^((\w|\s)+,)*(\w|\s)+$/', $str)) {
elseif (preg_match("/^({$and_wildcard}+,)*{$and_wildcard}+$/", $str)) {
$handler->operator = 'and';
$handler->value = explode(',', $str);
}

View File

@ -59,23 +59,42 @@ class HandlersTest extends ViewsSqlTest {
$this->assertEqual($handler, views_break_phrase_string('', $handler));
// test ors
$this->assertEqualValue(array('word1', 'word2', 'word'), views_break_phrase_string('word1 word2+word', $handler));
$handler = views_break_phrase_string('word1 word2+word');
$this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
$this->assertEqual('or', $handler->operator);
$this->assertEqualValue(array('word1', 'word2', 'word'), views_break_phrase_string('word1+word2+word', $handler));
$handler = views_break_phrase_string('word1+word2+word');
$this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
$this->assertEqual('or', $handler->operator);
$this->assertEqualValue(array('word1', 'word2', 'word'), views_break_phrase_string('word1 word2 word', $handler));
$handler = views_break_phrase_string('word1 word2 word');
$this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
$this->assertEqual('or', $handler->operator);
$this->assertEqualValue(array('word1', 'word2', 'word'), views_break_phrase_string('word1 word2++word', $handler));
$handler = views_break_phrase_string('word-1+word-2+word');
$this->assertEqualValue(array('word-1', 'word-2', 'word'), $handler);
$this->assertEqual('or', $handler->operator);
$handler = views_break_phrase_string('wõrd1+wõrd2+wõrd');
$this->assertEqualValue(array('wõrd1', 'wõrd2', 'wõrd'), $handler);
$this->assertEqual('or', $handler->operator);
// test ands.
$this->assertEqualValue(array('word1', 'word2', 'word'), views_break_phrase_string('word1,word2,word', $handler));
$handler = views_break_phrase_string('word1,word2,word');
$this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
$this->assertEqual('and', $handler->operator);
$this->assertEqualValue(array('word1', 'word2', 'word'), views_break_phrase_string('word1,,word2,word', $handler));
$handler = views_break_phrase_string('word1 word2,word');
$this->assertEqualValue(array('word1 word2', 'word'), $handler);
$this->assertEqual('and', $handler->operator);
$this->assertEqualValue(array('word1 word2', 'word'), views_break_phrase_string('word1 word2,word', $handler));
$handler = views_break_phrase_string('word1,word2 word');
$this->assertEqualValue(array('word1', 'word2 word'), $handler);
$this->assertEqual('and', $handler->operator);
$this->assertEqualValue(array('word1', 'word2 word'), views_break_phrase_string('word1,word2 word', $handler));
$handler = views_break_phrase_string('word-1,word-2,word');
$this->assertEqualValue(array('word-1', 'word-2', 'word'), $handler);
$this->assertEqual('and', $handler->operator);
$handler = views_break_phrase_string('wõrd1,wõrd2,wõrd');
$this->assertEqualValue(array('wõrd1', 'wõrd2', 'wõrd'), $handler);
$this->assertEqual('and', $handler->operator);
// test a single word
$handler = views_break_phrase_string('word');
$this->assertEqualValue(array('word'), $handler);
$this->assertEqual('and', $handler->operator);
}