Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 338e663

Browse filesBrowse files
BridgeARMylesBorins
authored andcommitted
assert: fix EOL issue in messages on Windows
PR-URL: #20754 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent 8e058d5 commit 338e663
Copy full SHA for 338e663

File tree

Expand file treeCollapse file tree

2 files changed

+28
-26
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+28
-26
lines changed
Open diff view settings
Collapse file

‎lib/assert.js‎

Copy file name to clipboardExpand all lines: lib/assert.js
+10-7Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ assert.fail = fail;
119119
assert.AssertionError = AssertionError;
120120

121121
function getBuffer(fd, assertLine) {
122-
var lines = 0;
122+
let lines = 0;
123123
// Prevent blocking the event loop by limiting the maximum amount of
124124
// data that may be read.
125-
var maxReads = 64; // bytesPerRead * maxReads = 512 kb
126-
var bytesRead = 0;
127-
var startBuffer = 0; // Start reading from that char on
125+
let maxReads = 64; // bytesPerRead * maxReads = 512 kb
126+
let bytesRead = 0;
127+
let startBuffer = 0; // Start reading from that char on
128128
const bytesPerRead = 8192;
129129
const buffers = [];
130130
do {
@@ -167,7 +167,7 @@ function getErrMessage(call) {
167167
return;
168168
}
169169

170-
var fd;
170+
let fd, message;
171171
try {
172172
fd = openSync(filename, 'r', 0o666);
173173
const buffers = getBuffer(fd, line);
@@ -186,11 +186,14 @@ function getErrMessage(call) {
186186
// not user defined function names.
187187
const ok = name === 'ok' ? '.ok' : '';
188188
const args = node.arguments;
189-
var message = code
189+
message = code
190190
.slice(args[0].start, args[args.length - 1].end)
191191
.replace(escapeSequencesRegExp, escapeFn);
192+
if (EOL === '\r\n') {
193+
message = message.replace(/\r\n/g, '\n');
194+
}
192195
message = 'The expression evaluated to a falsy value:' +
193-
`${EOL}${EOL} assert${ok}(${message})${EOL}`;
196+
`\n\n assert${ok}(${message})\n`;
194197
}
195198
// Make sure to always set the cache! No matter if the message is
196199
// undefined or not
Collapse file

‎test/parallel/test-assert.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-assert.js
+18-19Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
const common = require('../common');
2929
const assert = require('assert');
30-
const { EOL } = require('os');
3130
const EventEmitter = require('events');
3231
const { errorCache } = require('internal/assert');
3332
const { writeFileSync, unlinkSync } = require('fs');
@@ -462,8 +461,8 @@ assert.throws(
462461
{
463462
code: 'ERR_ASSERTION',
464463
type: assert.AssertionError,
465-
message: `The expression evaluated to a falsy value:${EOL}${EOL} ` +
466-
`assert.ok(typeof 123 === 'string')${EOL}`
464+
message: 'The expression evaluated to a falsy value:\n\n ' +
465+
"assert.ok(typeof 123 === 'string')\n"
467466
}
468467
);
469468
Error.stackTraceLimit = tmpLimit;
@@ -625,8 +624,8 @@ common.expectsError(
625624
code: 'ERR_ASSERTION',
626625
type: assert.AssertionError,
627626
generatedMessage: true,
628-
message: `The expression evaluated to a falsy value:${EOL}${EOL} ` +
629-
`assert.ok(null)${EOL}`
627+
message: 'The expression evaluated to a falsy value:\n\n ' +
628+
'assert.ok(null)\n'
630629
}
631630
);
632631
common.expectsError(
@@ -635,8 +634,8 @@ common.expectsError(
635634
code: 'ERR_ASSERTION',
636635
type: assert.AssertionError,
637636
generatedMessage: true,
638-
message: `The expression evaluated to a falsy value:${EOL}${EOL} ` +
639-
`assert(typeof 123 === 'string')${EOL}`
637+
message: 'The expression evaluated to a falsy value:\n\n ' +
638+
"assert(typeof 123 === 'string')\n"
640639
}
641640
);
642641

@@ -666,17 +665,17 @@ common.expectsError(
666665
{
667666
code: 'ERR_ASSERTION',
668667
type: assert.AssertionError,
669-
message: `The expression evaluated to a falsy value:${EOL}${EOL} ` +
670-
`assert(Buffer.from('test') instanceof Error)${EOL}`
668+
message: 'The expression evaluated to a falsy value:\n\n ' +
669+
"assert(Buffer.from('test') instanceof Error)\n"
671670
}
672671
);
673672
common.expectsError(
674673
() => throwErr(),
675674
{
676675
code: 'ERR_ASSERTION',
677676
type: assert.AssertionError,
678-
message: `The expression evaluated to a falsy value:${EOL}${EOL} ` +
679-
`assert(Buffer.from('test') instanceof Error)${EOL}`
677+
message: 'The expression evaluated to a falsy value:\n\n ' +
678+
"assert(Buffer.from('test') instanceof Error)\n"
680679
}
681680
);
682681
fs.close = tmp;
@@ -695,12 +694,12 @@ common.expectsError(
695694
{
696695
code: 'ERR_ASSERTION',
697696
type: assert.AssertionError,
698-
message: `The expression evaluated to a falsy value:${EOL}${EOL} ` +
699-
`assert((() => 'string')()${EOL}` +
700-
` // eslint-disable-next-line${EOL}` +
701-
` ===${EOL}` +
702-
` 123 instanceof${EOL}` +
703-
` Buffer)${EOL}`
697+
message: 'The expression evaluated to a falsy value:\n\n ' +
698+
"assert((() => 'string')()\n" +
699+
' // eslint-disable-next-line\n' +
700+
' ===\n' +
701+
' 123 instanceof\n' +
702+
' Buffer)\n'
704703
}
705704
);
706705

@@ -709,8 +708,8 @@ common.expectsError(
709708
{
710709
code: 'ERR_ASSERTION',
711710
type: assert.AssertionError,
712-
message: `The expression evaluated to a falsy value:${EOL}${EOL} ` +
713-
`assert(null, undefined)${EOL}`
711+
message: 'The expression evaluated to a falsy value:\n\n ' +
712+
'assert(null, undefined)\n'
714713
}
715714
);
716715

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.