From 10a85c7e032d35ee2da4de7973e463a4d7a0f4eb Mon Sep 17 00:00:00 2001 From: drothstein <drothstein@124982.no-reply.drupal.org> Date: Sun, 22 Jul 2012 19:20:24 +0200 Subject: [PATCH] Issue #1417400 by David_Rothstein | josaku: Fixed Various characters (UTF-8 characters, dashes, and symbols) cause views_break_phrase_string() not to work. --- includes/handlers.inc | 11 +++++--- lib/Drupal/views/Tests/HandlersTest.php | 35 +++++++++++++++++++------ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/includes/handlers.inc b/includes/handlers.inc index 771c36122580..8ae09f0d0b6b 100644 --- a/includes/handlers.inc +++ b/includes/handlers.inc @@ -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); } diff --git a/lib/Drupal/views/Tests/HandlersTest.php b/lib/Drupal/views/Tests/HandlersTest.php index 610fd62b199b..b44ce0cfda9d 100644 --- a/lib/Drupal/views/Tests/HandlersTest.php +++ b/lib/Drupal/views/Tests/HandlersTest.php @@ -59,23 +59,42 @@ function test_views_break_phrase_string() { $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); + $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); - $this->assertEqualValue(array('word1', 'word2 word'), views_break_phrase_string('word1,word2 word', $handler)); + $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); } -- GitLab