Skip to content

Commit

Permalink
Fix lower case key matching for arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuno Sousa authored and Francisco Cardoso committed Mar 24, 2017
1 parent e69fa4b commit df198a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 3 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Module dependencies.
*/

const { cloneDeepWith, isObject, some } = require('lodash');
const { cloneDeepWith, isObject, toLower, some } = require('lodash');

/**
* Export `maskJson` function.
Expand All @@ -15,13 +15,8 @@ module.exports = function maskJson(collection, {
} = {}) {
return function(values) {
return cloneDeepWith(values, (value, key) => {
// The top-most object has no key.
if (!key) {
return;
}

// Strip matching keys.
if (some(collection, (item) => ignoreCase ? key.toLowerCase() === item.toLowerCase() : key === item)) {
if (some(collection, item => ignoreCase ? toLower(key) === toLower(item) : key === item)) {
return replacement;
}

Expand All @@ -34,4 +29,4 @@ module.exports = function maskJson(collection, {
return value;
});
};
}
};
2 changes: 2 additions & 0 deletions test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const maskJson = require('../index');
describe('maskJson()', () => {
it('should accept a custom `ignoreCase`', () => {
const object = {
bar: ['biz', 'baz'],
foo: {
PaSSWorD: 'barbiz',
password: 'foobar',
Expand All @@ -20,6 +21,7 @@ describe('maskJson()', () => {
};

maskJson(['password', 'secret'], { ignoreCase: true })(object).should.eql({
bar: ['biz', 'baz'],
foo: {
PaSSWorD: '--REDACTED--',
password: '--REDACTED--',
Expand Down

0 comments on commit df198a1

Please sign in to comment.