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

Merge pull request #403 from gconsidine/ui/fix/host-search-with-spaces

Add support for quoted values containing spaces in search
This commit is contained in:
Greg Considine 2017-09-13 14:34:05 -04:00 committed by GitHub
commit 93927717c8
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() : "";
if(terms && terms !== '') {
// Split the terms up
let splitTerms = SmartSearchService.splitSearchIntoTerms(terms);
_.forEach(splitTerms, (term) => {
let splitTerms;
if ($scope.singleSearchParam === 'host_filter') {
splitTerms = SmartSearchService.splitHostIntoTerms(terms);
} else {
splitTerms = SmartSearchService.splitSearchIntoTerms(terms);
}
_.forEach(splitTerms, (term) => {
let termParts = SmartSearchService.splitTermIntoParts(term);
function combineSameSearches(a,b){

View File

@ -1,5 +1,34 @@
export default [function() {
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) {
return searchString.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g);
},