mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 02:19:58 -03:30
Add support for quoted without spaces and falsey input
This commit is contained in:
parent
57c9224b5c
commit
eab3cb8efd
@ -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}`;
|
||||
|
||||
|
||||
@ -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"]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user