Add support for quoted without spaces and falsey input

This commit is contained in:
gconsidine 2017-09-14 15:57:52 -04:00
parent 57c9224b5c
commit eab3cb8efd
No known key found for this signature in database
GPG Key ID: CC78E4D5913BB71D
2 changed files with 12 additions and 1 deletions

View File

@ -7,6 +7,10 @@ export default [function() {
* values before calling to `splitSearchIntoTerms`.
*/
splitFilterIntoTerms (searchString) {
if (!searchString) {
return null;
}
let groups = [];
let quoted;
@ -16,7 +20,11 @@ export default [function() {
searchString.split(' ').forEach(substring => {
if (substring.includes(':"')) {
quoted = substring;
if (/"$/.test(substring)) {
groups.push(this.encode(substring));
} else {
quoted = substring;
}
} else if (quoted) {
quoted += ` ${substring}`;

View File

@ -44,6 +44,7 @@ describe('Service: SmartSearch', () => {
describe('fn splitFilterIntoTerms', () => {
it('should convert the filter term to a key and value with encode quotes and spaces', () => {
expect(SmartSearchService.splitFilterIntoTerms()).toEqual(null);
expect(SmartSearchService.splitFilterIntoTerms('foo')).toEqual(["foo"]);
expect(SmartSearchService.splitFilterIntoTerms('foo bar')).toEqual(["foo", "bar"]);
expect(SmartSearchService.splitFilterIntoTerms('name:foo bar')).toEqual(["name:foo", "bar"]);
@ -54,6 +55,8 @@ describe('Service: SmartSearch', () => {
expect(SmartSearchService.splitFilterIntoTerms('name:"1"')).toEqual(["name:%221%22"]);
expect(SmartSearchService.splitFilterIntoTerms('name:1')).toEqual(["name:1"]);
expect(SmartSearchService.splitFilterIntoTerms(`name:"foo ba'r" a b c`)).toEqual(["name:%22foo%20ba%27r%22", 'a', 'b', 'c']);
expect(SmartSearchService.splitFilterIntoTerms('name:"foobar" other:"barbaz"')).toEqual(["name:%22foobar%22", "other:%22barbaz%22"]);
expect(SmartSearchService.splitFilterIntoTerms('name:"foobar" other:"bar baz"')).toEqual(["name:%22foobar%22", "other:%22bar%20baz%22"]);
});
});