mirror of
https://github.com/ansible/awx.git
synced 2026-03-21 19:07:39 -02:30
Escape name__regex and name__iregex (#11964)
Escape name__regex and name__iregex. Escaping the value for those keys when creating a smart inventory is a work around for the pyparsing code on the API side for special characters. This will just display an extra escape when showing the host_filter on details page.
This commit is contained in:
@@ -68,11 +68,12 @@ export function toQueryString(config, searchParams = {}) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Escape a string with double quote in case there was a white space
|
* Escape a string with double quote in case there was a white space
|
||||||
|
* @param {string} key The key of the value to be parsed
|
||||||
* @param {string} value A string to be parsed
|
* @param {string} value A string to be parsed
|
||||||
* @return {string} string
|
* @return {string} string
|
||||||
*/
|
*/
|
||||||
const escapeString = (value) => {
|
const escapeString = (key, value) => {
|
||||||
if (verifySpace(value)) {
|
if (verifySpace(value) || key.includes('regex')) {
|
||||||
return `"${value}"`;
|
return `"${value}"`;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
@@ -95,9 +96,11 @@ export function toHostFilter(searchParams = {}) {
|
|||||||
.sort()
|
.sort()
|
||||||
.flatMap((key) => {
|
.flatMap((key) => {
|
||||||
if (Array.isArray(searchParams[key])) {
|
if (Array.isArray(searchParams[key])) {
|
||||||
return searchParams[key].map((val) => `${key}=${escapeString(val)}`);
|
return searchParams[key].map(
|
||||||
|
(val) => `${key}=${escapeString(key, val)}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return `${key}=${escapeString(searchParams[key])}`;
|
return `${key}=${escapeString(key, searchParams[key])}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
const filteredSearchParams = flattenSearchParams.filter(
|
const filteredSearchParams = flattenSearchParams.filter(
|
||||||
|
|||||||
@@ -136,6 +136,17 @@ describe('toHostFilter', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should escape name__regex and name__iregex', () => {
|
||||||
|
const object = {
|
||||||
|
or__name__regex: '(t|e)st',
|
||||||
|
or__name__iregex: '(f|o)',
|
||||||
|
or__name: 'foo',
|
||||||
|
};
|
||||||
|
expect(toHostFilter(object)).toEqual(
|
||||||
|
'name=foo or name__iregex="(f|o)" or name__regex="(t|e)st"'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test('should return a host filter with or conditional when value is array', () => {
|
test('should return a host filter with or conditional when value is array', () => {
|
||||||
const object = {
|
const object = {
|
||||||
or__groups__id: ['1', '2'],
|
or__groups__id: ['1', '2'],
|
||||||
|
|||||||
Reference in New Issue
Block a user