mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Moving key match above recursion for removing branches
This commit is contained in:
parent
21a6660103
commit
71d65e4adb
2 changed files with 11 additions and 3 deletions
|
@ -21,6 +21,14 @@ describe('applyFilterToKey(obj, key, action)', function () {
|
|||
});
|
||||
});
|
||||
|
||||
it('should remove an entire branch', function () {
|
||||
var data = fixture();
|
||||
applyFilterToKey(data, 'headers', 'remove');
|
||||
expect(data).to.eql({
|
||||
req: { }
|
||||
});
|
||||
});
|
||||
|
||||
it('should censor a key in an object recursivly', function () {
|
||||
var data = fixture();
|
||||
applyFilterToKey(data, 'authorization', 'censor');
|
||||
|
|
|
@ -6,9 +6,7 @@ module.exports = function applyFilterToKey(obj, key, action) {
|
|||
for (let k in obj) {
|
||||
if (obj.hasOwnProperty(k)) {
|
||||
let val = obj[k];
|
||||
if (typeof val === 'object') {
|
||||
applyFilterToKey(val, key, action);
|
||||
} else if (k === key) {
|
||||
if (k === key) {
|
||||
val = '' + val;
|
||||
if (action === 'remove') delete obj[k];
|
||||
if (action === 'censor') {
|
||||
|
@ -17,6 +15,8 @@ module.exports = function applyFilterToKey(obj, key, action) {
|
|||
if (action instanceof RegExp) {
|
||||
obj[k] = val.replace(action, replacer);
|
||||
}
|
||||
} else if (typeof val === 'object') {
|
||||
applyFilterToKey(val, key, action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue