Summary: Certain unusual queries, like `[-]`, could tokenize into a list which included the empty string. This would then convert into a query for `... LIKE "%"` which just joins the entire table. Instead: tokenize smarter; never return the empty token; add some test cases. Test Plan: Ran unit tests. Queried for `[[blah blah]]`, saw a reasonable query come out the other end. Reviewers: chad Reviewed By: chad Subscribers: 20after4 Differential Revision: https://secure.phabricator.com/D16888
40 lines
873 B
PHP
40 lines
873 B
PHP
<?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));
|
|
}
|
|
|
|
}
|