Page MenuHomePhabricator

D16888.diff
No OneTemporary

D16888.diff

diff --git a/PhabricatorTypeaheadDatasourceTestCase.php b/PhabricatorTypeaheadDatasourceTestCase.php
new file mode 100644
--- /dev/null
+++ b/PhabricatorTypeaheadDatasourceTestCase.php
@@ -0,0 +1,39 @@
+<?php
+
+final class PhabricatorTypeaheadDatasourceTestCase
+ extends PhabricatorTestCase {
+
+ public function testTypeaheadTokenization() {
+ $this->assertTokenization(
+ 'The quick brown fox',
+ array('the', 'quick', 'brown', 'fox'));
+
+ $this->assertTokenization(
+ 'Quack quack QUACK',
+ array('quack'));
+
+ $this->assertTokenization(
+ '',
+ array());
+
+ $this->assertTokenization(
+ ' [ - ] ',
+ array());
+
+ $this->assertTokenization(
+ 'jury-rigged',
+ array('jury', 'rigged'));
+
+ $this->assertTokenization(
+ '[[ brackets ]] [-] ]-[ tie-fighters',
+ array('brackets', 'tie', 'fighters'));
+ }
+
+ private function assertTokenization($input, $expect) {
+ $this->assertEqual(
+ $expect,
+ PhabricatorTypeaheadDatasource::tokenizeString($input),
+ pht('Tokenization of "%s"', $input));
+ }
+
+}
diff --git a/src/applications/typeahead/datasource/PhabricatorTypeaheadDatasource.php b/src/applications/typeahead/datasource/PhabricatorTypeaheadDatasource.php
--- a/src/applications/typeahead/datasource/PhabricatorTypeaheadDatasource.php
+++ b/src/applications/typeahead/datasource/PhabricatorTypeaheadDatasource.php
@@ -141,8 +141,18 @@
return array();
}
- $tokens = preg_split('/\s+|[-\[\]]/u', $string);
- return array_unique($tokens);
+ $tokens = preg_split('/[\s\[\]-]+/u', $string);
+ $tokens = array_unique($tokens);
+
+ // Make sure we don't return the empty token, as this will boil down to a
+ // JOIN against every token.
+ foreach ($tokens as $key => $value) {
+ if (!strlen($value)) {
+ unset($tokens[$key]);
+ }
+ }
+
+ return array_values($tokens);
}
public function getTokens() {

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 6, 11:38 PM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6729560
Default Alt Text
D16888.diff (1 KB)

Event Timeline