Skip to content

Commit

Permalink
fix: crash on attempt to uncolorize Symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexsey authored and wbt committed Jul 5, 2022
1 parent bbd7497 commit a3388f0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions test/uncolorize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ describe('uncolorize', () => {
}
));

it('uncolorize() not crashing with Symbol()', assumeFormatted(
combine(
format(info => {
info.level = info.level.toUpperCase();
return info;
})(),
colorize(),
uncolorize()
),
infoify({ level: 'info', message: Symbol() }),
info => {
assume(info.level).is.a('string');
assume(info.message).is.a('string');

assume(info.level).equals('INFO');
assume(info.message).equals('Symbol()');
}
));

it('uncolorize({ level: false }) removes color from { message, [MESSAGE] }', assumeFormatted(
addAndRemoveColors({ level: false }),
infoify({ level: 'info', message: 'whatever' }),
Expand Down
4 changes: 2 additions & 2 deletions uncolorize.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ module.exports = format((info, opts) => {
}

if (opts.message !== false) {
info.message = colors.strip(info.message);
info.message = colors.strip(String(info.message));
}

if (opts.raw !== false && info[MESSAGE]) {
info[MESSAGE] = colors.strip(info[MESSAGE]);
info[MESSAGE] = colors.strip(String(info[MESSAGE]));
}

return info;
Expand Down

0 comments on commit a3388f0

Please sign in to comment.