From eab3cb8efdd95c40050e44ffa098d7d5aa49fe8c Mon Sep 17 00:00:00 2001 From: gconsidine Date: Thu, 14 Sep 2017 15:57:52 -0400 Subject: [PATCH] Add support for quoted without spaces and falsey input --- .../src/shared/smart-search/smart-search.service.js | 10 +++++++++- .../spec/smart-search/smart-search.service-test.js | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/awx/ui/client/src/shared/smart-search/smart-search.service.js b/awx/ui/client/src/shared/smart-search/smart-search.service.js index 3e97ec45e3..ffaa95bc8c 100644 --- a/awx/ui/client/src/shared/smart-search/smart-search.service.js +++ b/awx/ui/client/src/shared/smart-search/smart-search.service.js @@ -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}`; diff --git a/awx/ui/tests/spec/smart-search/smart-search.service-test.js b/awx/ui/tests/spec/smart-search/smart-search.service-test.js index a6441719f1..6c2ad05f09 100644 --- a/awx/ui/tests/spec/smart-search/smart-search.service-test.js +++ b/awx/ui/tests/spec/smart-search/smart-search.service-test.js @@ -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"]); }); });