1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 15:21:13 +03:00

Replace use of string.includes due lack of browser support

This commit is contained in:
gconsidine 2017-09-14 17:27:27 -04:00
parent eab3cb8efd
commit dd62e8ce92
No known key found for this signature in database
GPG Key ID: CC78E4D5913BB71D
2 changed files with 3 additions and 7 deletions

View File

@ -14,12 +14,8 @@ export default [function() {
let groups = []; let groups = [];
let quoted; let quoted;
if (!searchString.includes(' ')) {
return this.splitSearchIntoTerms(this.encode(searchString));
}
searchString.split(' ').forEach(substring => { searchString.split(' ').forEach(substring => {
if (substring.includes(':"')) { if (/:"/g.test(substring)) {
if (/"$/.test(substring)) { if (/"$/.test(substring)) {
groups.push(this.encode(substring)); groups.push(this.encode(substring));
} else { } else {
@ -28,7 +24,7 @@ export default [function() {
} else if (quoted) { } else if (quoted) {
quoted += ` ${substring}`; quoted += ` ${substring}`;
if (substring.includes('"')) { if (/"/g.test(substring)) {
groups.push(this.encode(quoted)); groups.push(this.encode(quoted));
quoted = undefined; quoted = undefined;
} }

View File

@ -54,7 +54,7 @@ describe('Service: SmartSearch', () => {
expect(SmartSearchService.splitFilterIntoTerms('name:"foo bar" a b c')).toEqual(["name:%22foo%20bar%22", 'a', 'b', 'c']); expect(SmartSearchService.splitFilterIntoTerms('name:"foo bar" a b c')).toEqual(["name:%22foo%20bar%22", 'a', 'b', 'c']);
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:"barbaz"')).toEqual(["name:%22foobar%22", "other:%22barbaz%22"]);
expect(SmartSearchService.splitFilterIntoTerms('name:"foobar" other:"bar baz"')).toEqual(["name:%22foobar%22", "other:%22bar%20baz%22"]); expect(SmartSearchService.splitFilterIntoTerms('name:"foobar" other:"bar baz"')).toEqual(["name:%22foobar%22", "other:%22bar%20baz%22"]);
}); });