Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip masking non-strings #10

Merged
merged 1 commit into from
Sep 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the syntax <object>.should… when possible please.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would also fail with a TypeError: Cannot read property 'should' of undefined

});
});

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