mirror of
https://github.com/ansible/awx.git
synced 2026-05-12 20:07:37 -02:30
Merge pull request #3608 from mabashian/host-filter-quotes
Prevents replacing encoded quotes while searching against host filter Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
@@ -18,11 +18,11 @@ function QuerysetService ($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearc
|
|||||||
return defer.promise;
|
return defer.promise;
|
||||||
},
|
},
|
||||||
getCommonModelOptions(path, name) {
|
getCommonModelOptions(path, name) {
|
||||||
let resolve, base,
|
let base,
|
||||||
defer = $q.defer();
|
defer = $q.defer();
|
||||||
|
|
||||||
this.url = path;
|
this.url = path;
|
||||||
resolve = this.options(path)
|
this.options(path)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
base = res.data.actions.GET;
|
base = res.data.actions.GET;
|
||||||
let relatedSearchFields = res.data.related_search_fields;
|
let relatedSearchFields = res.data.related_search_fields;
|
||||||
@@ -46,7 +46,7 @@ function QuerysetService ($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearc
|
|||||||
replaceEncodedTokens(value) {
|
replaceEncodedTokens(value) {
|
||||||
return decodeURIComponent(value).replace(/"|'/g, "");
|
return decodeURIComponent(value).replace(/"|'/g, "");
|
||||||
},
|
},
|
||||||
encodeTerms(value, key){
|
encodeTerms(value, key, singleSearchParam){
|
||||||
key = this.replaceDefaultFlags(key);
|
key = this.replaceDefaultFlags(key);
|
||||||
value = this.replaceDefaultFlags(value);
|
value = this.replaceDefaultFlags(value);
|
||||||
var that = this;
|
var that = this;
|
||||||
@@ -54,7 +54,7 @@ function QuerysetService ($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearc
|
|||||||
value = _.uniq(_.flattenDeep(value));
|
value = _.uniq(_.flattenDeep(value));
|
||||||
let concated = '';
|
let concated = '';
|
||||||
angular.forEach(value, function(item){
|
angular.forEach(value, function(item){
|
||||||
if(item && typeof item === 'string') {
|
if(item && typeof item === 'string' && !singleSearchParam) {
|
||||||
item = that.replaceEncodedTokens(item);
|
item = that.replaceEncodedTokens(item);
|
||||||
}
|
}
|
||||||
concated += `${key}=${item}&`;
|
concated += `${key}=${item}&`;
|
||||||
@@ -63,7 +63,7 @@ function QuerysetService ($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearc
|
|||||||
return concated;
|
return concated;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(value && typeof value === 'string') {
|
if(value && typeof value === 'string' && !singleSearchParam) {
|
||||||
value = this.replaceEncodedTokens(value);
|
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
|
// encodes ui-router params from {operand__key__comparator: value} pairs to API-consumable URL
|
||||||
encodeQueryset(params) {
|
encodeQueryset(params, singleSearchParam) {
|
||||||
let queryset;
|
let queryset;
|
||||||
queryset = _.reduce(params, (result, value, key) => {
|
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);
|
queryset = queryset.substring(0, queryset.length - 1);
|
||||||
return angular.isObject(params) ? `?${queryset}` : '';
|
return angular.isObject(params) ? `?${queryset}` : '';
|
||||||
@@ -268,9 +268,9 @@ function QuerysetService ($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearc
|
|||||||
Rest.setUrl(endpoint);
|
Rest.setUrl(endpoint);
|
||||||
return Rest.options(endpoint);
|
return Rest.options(endpoint);
|
||||||
},
|
},
|
||||||
search(endpoint, params) {
|
search(endpoint, params, singleSearchParam) {
|
||||||
Wait('start');
|
Wait('start');
|
||||||
this.url = `${endpoint}${this.encodeQueryset(params)}`;
|
this.url = `${endpoint}${this.encodeQueryset(params, singleSearchParam)}`;
|
||||||
Rest.setUrl(this.url);
|
Rest.setUrl(this.url);
|
||||||
|
|
||||||
return Rest.get()
|
return Rest.get()
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ function SmartSearchController (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
qs.search(path, queryset)
|
qs.search(path, queryset, singleSearchParam)
|
||||||
.then(({ data }) => {
|
.then(({ data }) => {
|
||||||
if ($scope.querySet) {
|
if ($scope.querySet) {
|
||||||
$scope.querySet = queryset;
|
$scope.querySet = queryset;
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ export default [function() {
|
|||||||
let groups = [];
|
let groups = [];
|
||||||
let quoted;
|
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 => {
|
searchString.split(' ').forEach(substring => {
|
||||||
if (/:"/g.test(substring)) {
|
if (/:"/g.test(substring)) {
|
||||||
if (/"$/.test(substring)) {
|
if (/"$/.test(substring)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user