From 1a4e9ff4128b3aefe6b57e77a3456813dea6f28a Mon Sep 17 00:00:00 2001 From: Steven Hargrove Date: Tue, 20 Feb 2018 11:34:34 -0500 Subject: [PATCH] added logic to correctly print stringified linebreak chars (#5360) --- src/reporters/base-reporter.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/reporters/base-reporter.js b/src/reporters/base-reporter.js index 673a48ddcb..2bf1248655 100644 --- a/src/reporters/base-reporter.js +++ b/src/reporters/base-reporter.js @@ -17,6 +17,7 @@ import type {Formatter} from './format.js'; import {defaultFormatter} from './format.js'; import * as languages from './lang/index.js'; import isCI from 'is-ci'; +import os from 'os'; const util = require('util'); const EventEmitter = require('events').EventEmitter; @@ -41,9 +42,10 @@ export function stringifyLangArgs(args: Array): Array { } else { try { const str = JSON.stringify(val) || val + ''; - // should match all "u001b" that follow an odd number of backslashes and convert them to ESC + // should match all literal line breaks and + // "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'); + return str.replace(/((?:^|[^\\])(?:\\{2})*)\\u001[bB]/g, '$1\u001b').replace(/[\\]r[\\]n|[\\]n/g, os.EOL); } catch (e) { return util.inspect(val); }