Skip to content

Commit

Permalink
added logic to correctly print stringified linebreak chars (#5360)
Browse files Browse the repository at this point in the history
  • Loading branch information
hulkish authored and arcanis committed Feb 20, 2018
1 parent 204f2f6 commit 1a4e9ff
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/reporters/base-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,9 +42,10 @@ export function stringifyLangArgs(args: Array<any>): Array<string> {
} 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);
}
Expand Down

0 comments on commit 1a4e9ff

Please sign in to comment.