Page MenuHomePhabricator

D16888.id.diff
No OneTemporary

D16888.id.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
Fri, Dec 20, 3:02 AM (20 h, 15 s)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6909304
Default Alt Text
D16888.id.diff (1 KB)

Event Timeline