Skip to content

Commit

Permalink
Skip masking non-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
filipefigcorreia committed Sep 27, 2017
1 parent db972b1 commit e86fc35
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ module.exports = (elements, {
replacement = '--REDACTED--'
} = {}) => {
return value => {
if (typeof value !== 'string') {
return value;
}

for (const element of elements) {
const search = new RegExp(`<(${element})>(.+)</(${element})>`, `g${ignoreCase ? 'i' : ''}`);

Expand Down
7 changes: 7 additions & 0 deletions test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

const maskXml = require('../index');
const should = require('should');

/**
* Test `maskXml`.
Expand Down Expand Up @@ -44,6 +45,12 @@ describe('maskXml()', () => {
`);
});

it('should skip masking non-strings', () => {
[undefined, { biz: 'baz' }, 42].forEach(nonString => {
should(maskXml(['foo'])(nonString)).equal(nonString);
});
});

it('should mask the given xml string', () => {
const xml = `
<xml>
Expand Down

0 comments on commit e86fc35

Please sign in to comment.