Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14347462
D16888.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D16888.id.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D16888: Prevent typeahead sources from querying against empty tokens
Attached
Detach File
Event Timeline
Log In to Comment