mirror of
https://github.com/ansible/awx.git
synced 2026-04-09 03:59:21 -02:30
update qs utils to allow empty string params
This commit is contained in:
@@ -159,7 +159,7 @@ export function removeParams(config, oldParams, paramsToRemove) {
|
|||||||
};
|
};
|
||||||
Object.keys(oldParams).forEach(key => {
|
Object.keys(oldParams).forEach(key => {
|
||||||
const value = removeParam(oldParams[key], paramsToRemove[key]);
|
const value = removeParam(oldParams[key], paramsToRemove[key]);
|
||||||
if (value) {
|
if (value !== null) {
|
||||||
updated[key] = value;
|
updated[key] = value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -205,7 +205,7 @@ export function mergeParams(oldParams, newParams) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mergeParam(oldVal, newVal) {
|
function mergeParam(oldVal, newVal) {
|
||||||
if (!newVal) {
|
if (!newVal && newVal !== '') {
|
||||||
return oldVal;
|
return oldVal;
|
||||||
}
|
}
|
||||||
if (!oldVal) {
|
if (!oldVal) {
|
||||||
|
|||||||
@@ -310,6 +310,21 @@ describe('qs (qs.js)', () => {
|
|||||||
page_size: 15,
|
page_size: 15,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should parse empty string values', () => {
|
||||||
|
const config = {
|
||||||
|
namespace: 'bee',
|
||||||
|
defaultParams: { page: 1, page_size: 15 },
|
||||||
|
integerFields: ['page', 'page_size'],
|
||||||
|
};
|
||||||
|
const query = '?bee.baz=bar&bee.or__source=';
|
||||||
|
expect(parseQueryString(config, query)).toEqual({
|
||||||
|
baz: 'bar',
|
||||||
|
page: 1,
|
||||||
|
page_size: 15,
|
||||||
|
or__source: '',
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('removeParams', () => {
|
describe('removeParams', () => {
|
||||||
@@ -532,6 +547,21 @@ describe('qs (qs.js)', () => {
|
|||||||
page_size: 15,
|
page_size: 15,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should retain empty string', () => {
|
||||||
|
const config = {
|
||||||
|
namespace: null,
|
||||||
|
defaultParams: { page: 1, page_size: 15 },
|
||||||
|
integerFields: ['page', 'page_size'],
|
||||||
|
};
|
||||||
|
const oldParams = { baz: '', page: 3, bag: 'boom', page_size: 15 };
|
||||||
|
const toRemove = { bag: 'boom' };
|
||||||
|
expect(removeParams(config, oldParams, toRemove)).toEqual({
|
||||||
|
baz: '',
|
||||||
|
page: 3,
|
||||||
|
page_size: 15,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('_stringToObject', () => {
|
describe('_stringToObject', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user