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

Add support for quoted values containing spaces in search

This commit is contained in:
gconsidine 2017-09-12 14:57:07 -04:00
parent 6068eafeb6
commit 87eab79f70
No known key found for this signature in database
GPG Key ID: CC78E4D5913BB71D
2 changed files with 37 additions and 3 deletions

View File

@ -161,10 +161,15 @@ export default ['$stateParams', '$scope', '$state', 'GetBasePath', 'QuerySet', '
terms = (terms) ? terms.trim() : ""; terms = (terms) ? terms.trim() : "";
if(terms && terms !== '') { if(terms && terms !== '') {
// Split the terms up let splitTerms;
let splitTerms = SmartSearchService.splitSearchIntoTerms(terms);
_.forEach(splitTerms, (term) => {
if ($scope.singleSearchParam === 'host_filter') {
splitTerms = SmartSearchService.splitHostIntoTerms(terms);
} else {
splitTerms = SmartSearchService.splitSearchIntoTerms(terms);
}
_.forEach(splitTerms, (term) => {
let termParts = SmartSearchService.splitTermIntoParts(term); let termParts = SmartSearchService.splitTermIntoParts(term);
function combineSameSearches(a,b){ function combineSameSearches(a,b){

View File

@ -1,5 +1,34 @@
export default [function() { export default [function() {
return { return {
/**
* For the Smart Host Filter, values with spaces are wrapped with double quotes on input.
* To avoid having these quoted values split up and treated as terms themselves, some
* work is done to encode quotes in quoted values and the spaces within those quoted
* values before calling to `splitSearchIntoTerms`.
*/
splitHostIntoTerms (searchString) {
let groups = [];
let quoted;
searchString.split(' ').forEach(substring => {
if (substring.includes(':"')) {
quoted = substring;
} else if (quoted) {
quoted += ` ${substring}`;
if (substring.includes('"')) {
quoted = quoted.replace(/"/g, encodeURIComponent('"'));
quoted = quoted.replace(/ /g, encodeURIComponent(' '));
groups.push(quoted);
quoted = undefined;
}
} else {
groups.push(substring);
}
});
return this.splitSearchIntoTerms(groups.join(' '));
},
splitSearchIntoTerms(searchString) { splitSearchIntoTerms(searchString) {
return searchString.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g); return searchString.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g);
}, },