From 47d6e5c0285d87048563e2a484568380d87d005d Mon Sep 17 00:00:00 2001 From: mabashian Date: Wed, 3 Apr 2019 15:17:41 -0400 Subject: [PATCH 1/2] Prevents replacing encoded quotes while searching against host filter --- .../shared/smart-search/queryset.service.js | 18 +++++++++--------- .../smart-search/smart-search.controller.js | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/awx/ui/client/src/shared/smart-search/queryset.service.js b/awx/ui/client/src/shared/smart-search/queryset.service.js index db21251dd1..2db940b94c 100644 --- a/awx/ui/client/src/shared/smart-search/queryset.service.js +++ b/awx/ui/client/src/shared/smart-search/queryset.service.js @@ -18,11 +18,11 @@ function QuerysetService ($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearc return defer.promise; }, getCommonModelOptions(path, name) { - let resolve, base, + let base, defer = $q.defer(); this.url = path; - resolve = this.options(path) + this.options(path) .then((res) => { base = res.data.actions.GET; let relatedSearchFields = res.data.related_search_fields; @@ -46,7 +46,7 @@ function QuerysetService ($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearc replaceEncodedTokens(value) { return decodeURIComponent(value).replace(/"|'/g, ""); }, - encodeTerms(value, key){ + encodeTerms(value, key, singleSearchParam){ key = this.replaceDefaultFlags(key); value = this.replaceDefaultFlags(value); var that = this; @@ -54,7 +54,7 @@ function QuerysetService ($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearc value = _.uniq(_.flattenDeep(value)); let concated = ''; angular.forEach(value, function(item){ - if(item && typeof item === 'string') { + if(item && typeof item === 'string' && !singleSearchParam) { item = that.replaceEncodedTokens(item); } concated += `${key}=${item}&`; @@ -63,7 +63,7 @@ function QuerysetService ($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearc return concated; } else { - if(value && typeof value === 'string') { + if(value && typeof value === 'string' && !singleSearchParam) { value = this.replaceEncodedTokens(value); } @@ -71,10 +71,10 @@ function QuerysetService ($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearc } }, // encodes ui-router params from {operand__key__comparator: value} pairs to API-consumable URL - encodeQueryset(params) { + encodeQueryset(params, singleSearchParam) { let queryset; queryset = _.reduce(params, (result, value, key) => { - return result + this.encodeTerms(value, key); + return result + this.encodeTerms(value, key, singleSearchParam); }, ''); queryset = queryset.substring(0, queryset.length - 1); return angular.isObject(params) ? `?${queryset}` : ''; @@ -268,9 +268,9 @@ function QuerysetService ($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearc Rest.setUrl(endpoint); return Rest.options(endpoint); }, - search(endpoint, params) { + search(endpoint, params, singleSearchParam) { Wait('start'); - this.url = `${endpoint}${this.encodeQueryset(params)}`; + this.url = `${endpoint}${this.encodeQueryset(params, singleSearchParam)}`; Rest.setUrl(this.url); return Rest.get() diff --git a/awx/ui/client/src/shared/smart-search/smart-search.controller.js b/awx/ui/client/src/shared/smart-search/smart-search.controller.js index 2109b1e03e..80aabc22e9 100644 --- a/awx/ui/client/src/shared/smart-search/smart-search.controller.js +++ b/awx/ui/client/src/shared/smart-search/smart-search.controller.js @@ -202,7 +202,7 @@ function SmartSearchController ( }); } - qs.search(path, queryset) + qs.search(path, queryset, singleSearchParam) .then(({ data }) => { if ($scope.querySet) { $scope.querySet = queryset; From d9d3c5d15f6741bc95aa78de028856094bed3248 Mon Sep 17 00:00:00 2001 From: mabashian Date: Wed, 3 Apr 2019 16:56:36 -0400 Subject: [PATCH 2/2] Adds comment explaining logic following the split on empty string in splitFilterIntoTerms --- awx/ui/client/src/shared/smart-search/smart-search.service.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/awx/ui/client/src/shared/smart-search/smart-search.service.js b/awx/ui/client/src/shared/smart-search/smart-search.service.js index 8e7b57271d..fc540c3573 100644 --- a/awx/ui/client/src/shared/smart-search/smart-search.service.js +++ b/awx/ui/client/src/shared/smart-search/smart-search.service.js @@ -14,6 +14,10 @@ export default [function() { let groups = []; let quoted; + // This split _may_ split search terms down the middle + // ex) searchString=ansible_facts.some_other_thing:"foo foobar" ansible_facts.some_thing:"foobar" + // would result in 3 different substring's but only two search terms + // This logic handles that scenario with the `quoted` variable searchString.split(' ').forEach(substring => { if (/:"/g.test(substring)) { if (/"$/.test(substring)) {