From 3c459de1b0f3a2074feaa5cb889d8c989a644172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Tue, 21 Feb 2017 18:19:33 +0000 Subject: [PATCH] Unescapes ESC character, fixing #2439 (#2745) --- __tests__/reporters/base-reporter.js | 6 ++++++ src/reporters/base-reporter.js | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/__tests__/reporters/base-reporter.js b/__tests__/reporters/base-reporter.js index 53a45e3ed7..636e27f954 100644 --- a/__tests__/reporters/base-reporter.js +++ b/__tests__/reporters/base-reporter.js @@ -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); +}); diff --git a/src/reporters/base-reporter.js b/src/reporters/base-reporter.js index 722158d914..b65bff3e67 100644 --- a/src/reporters/base-reporter.js +++ b/src/reporters/base-reporter.js @@ -37,7 +37,10 @@ export function stringifyLangArgs(args: Array): Array { 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); }