diff --git a/index.js b/index.js index ff1b0cb..5e6dc41 100644 --- a/index.js +++ b/index.js @@ -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})>(.+)`, `g${ignoreCase ? 'i' : ''}`); diff --git a/test/index_test.js b/test/index_test.js index 686afe7..c93b383 100644 --- a/test/index_test.js +++ b/test/index_test.js @@ -4,6 +4,7 @@ */ const maskXml = require('../index'); +const should = require('should'); /** * Test `maskXml`. @@ -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 = `