mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 15:36:04 -03:30
Add support for quoted without spaces and falsey input
This commit is contained in:
@@ -7,6 +7,10 @@ export default [function() {
|
|||||||
* values before calling to `splitSearchIntoTerms`.
|
* values before calling to `splitSearchIntoTerms`.
|
||||||
*/
|
*/
|
||||||
splitFilterIntoTerms (searchString) {
|
splitFilterIntoTerms (searchString) {
|
||||||
|
if (!searchString) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
let groups = [];
|
let groups = [];
|
||||||
let quoted;
|
let quoted;
|
||||||
|
|
||||||
@@ -16,7 +20,11 @@ export default [function() {
|
|||||||
|
|
||||||
searchString.split(' ').forEach(substring => {
|
searchString.split(' ').forEach(substring => {
|
||||||
if (substring.includes(':"')) {
|
if (substring.includes(':"')) {
|
||||||
quoted = substring;
|
if (/"$/.test(substring)) {
|
||||||
|
groups.push(this.encode(substring));
|
||||||
|
} else {
|
||||||
|
quoted = substring;
|
||||||
|
}
|
||||||
} else if (quoted) {
|
} else if (quoted) {
|
||||||
quoted += ` ${substring}`;
|
quoted += ` ${substring}`;
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ describe('Service: SmartSearch', () => {
|
|||||||
|
|
||||||
describe('fn splitFilterIntoTerms', () => {
|
describe('fn splitFilterIntoTerms', () => {
|
||||||
it('should convert the filter term to a key and value with encode quotes and spaces', () => {
|
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')).toEqual(["foo"]);
|
||||||
expect(SmartSearchService.splitFilterIntoTerms('foo bar')).toEqual(["foo", "bar"]);
|
expect(SmartSearchService.splitFilterIntoTerms('foo bar')).toEqual(["foo", "bar"]);
|
||||||
expect(SmartSearchService.splitFilterIntoTerms('name:foo bar')).toEqual(["name: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:%221%22"]);
|
||||||
expect(SmartSearchService.splitFilterIntoTerms('name:1')).toEqual(["name:1"]);
|
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:"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"]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user