Skip to content

Commit

Permalink
Unescapes ESC character, fixing #2439 (#2745)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis authored and bestander committed Feb 21, 2017
1 parent 7aaee9b commit 3c459de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions __tests__/reporters/base-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,9 @@ test('BaseReporter.disableProgress', () => {
reporter.disableProgress();
expect(reporter.noProgress).toBeTruthy();
});

test('BaseReporter.termstrings', () => {
const reporter = new BaseReporter();
const expected = '"\u001b[2mjsprim#\u001b[22mjson-schema" not installed';
expect(reporter.lang('packageNotInstalled', '\u001b[2mjsprim#\u001b[22mjson-schema')).toEqual(expected);
});
5 changes: 4 additions & 1 deletion src/reporters/base-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export function stringifyLangArgs(args: Array<any>): Array<string> {
return val.inspect();
} else {
try {
return JSON.stringify(val) || val + '';
const str = JSON.stringify(val) || val + '';
// should match all "u001b" that follow an odd number of backslashes and convert them to ESC
// we do this because the JSON.stringify process has escaped these characters
return str.replace(/((?:^|[^\\])(?:\\{2})*)\\u001[bB]/g, '$1\u001b');
} catch (e) {
return util.inspect(val);
}
Expand Down

0 comments on commit 3c459de

Please sign in to comment.