@@ -242,7 +242,7 @@ function REPLServer(prompt,
242
242
var err , result , retry = false , input = code , wrappedErr ;
243
243
// first, create the Script object to check the syntax
244
244
245
- if ( code === '\n' )
245
+ if ( code === '\n' || code === '\r\n' )
246
246
return cb ( null ) ;
247
247
248
248
while ( true ) {
@@ -251,7 +251,7 @@ function REPLServer(prompt,
251
251
( self . replMode === exports . REPL_MODE_STRICT || retry ) ) {
252
252
// "void 0" keeps the repl from returning "use strict" as the
253
253
// result value for let/const statements.
254
- code = `'use strict'; void 0;\n${ code } ` ;
254
+ code = `'use strict'; void 0;\r\ n${ code } ` ;
255
255
}
256
256
var script = vm . createScript ( code , {
257
257
filename : file ,
@@ -265,7 +265,7 @@ function REPLServer(prompt,
265
265
if ( self . wrappedCmd ) {
266
266
self . wrappedCmd = false ;
267
267
// unwrap and try again
268
- code = `${ input . substring ( 1 , input . length - 2 ) } \n` ;
268
+ code = `${ input . substring ( 1 , input . length - 2 ) } \r\ n` ;
269
269
wrappedErr = e ;
270
270
} else {
271
271
retry = true ;
@@ -367,7 +367,7 @@ function REPLServer(prompt,
367
367
e . stack = e . stack . replace ( / ( \s + a t \s + r e p l : ) ( \d + ) / ,
368
368
( _ , pre , line ) => pre + ( line - 1 ) ) ;
369
369
}
370
- top . outputStream . write ( ( e . stack || e ) + '\n' ) ;
370
+ top . outputStream . write ( ( e . stack || e ) + '\r\ n' ) ;
371
371
top . lineParser . reset ( ) ;
372
372
top . bufferedCommand = '' ;
373
373
top . lines . level = [ ] ;
@@ -453,7 +453,7 @@ function REPLServer(prompt,
453
453
sawSIGINT = false ;
454
454
return ;
455
455
}
456
- self . output . write ( '(To exit, press ^C again or type .exit)\n' ) ;
456
+ self . output . write ( '(To exit, press ^C again or type .exit)\r\ n' ) ;
457
457
sawSIGINT = true ;
458
458
} else {
459
459
sawSIGINT = false ;
@@ -470,7 +470,7 @@ function REPLServer(prompt,
470
470
sawSIGINT = false ;
471
471
472
472
if ( self . editorMode ) {
473
- self . bufferedCommand += cmd + '\n' ;
473
+ self . bufferedCommand += cmd + '\r\ n' ;
474
474
return ;
475
475
}
476
476
@@ -490,7 +490,7 @@ function REPLServer(prompt,
490
490
if ( self . parseREPLKeyword ( keyword , rest ) === true ) {
491
491
return ;
492
492
} else if ( ! self . bufferedCommand ) {
493
- self . outputStream . write ( 'Invalid REPL keyword\n' ) ;
493
+ self . outputStream . write ( 'Invalid REPL keyword\r\ n' ) ;
494
494
finish ( null ) ;
495
495
return ;
496
496
}
@@ -509,8 +509,8 @@ function REPLServer(prompt,
509
509
self . wrappedCmd = false ;
510
510
if ( e && ! self . bufferedCommand && cmd . trim ( ) . startsWith ( 'npm ' ) ) {
511
511
self . outputStream . write ( 'npm should be run outside of the ' +
512
- 'node repl, in your normal shell.\n' +
513
- '(Press Control-D to exit.)\n' ) ;
512
+ 'node repl, in your normal shell.\r\ n' +
513
+ '(Press Control-D to exit.)\r\ n' ) ;
514
514
self . lineParser . reset ( ) ;
515
515
self . bufferedCommand = '' ;
516
516
self . displayPrompt ( ) ;
@@ -525,7 +525,7 @@ function REPLServer(prompt,
525
525
// {
526
526
// ... x: 1
527
527
// ... }
528
- self . bufferedCommand += cmd + '\n' ;
528
+ self . bufferedCommand += cmd + '\r\ n' ;
529
529
self . displayPrompt ( ) ;
530
530
return ;
531
531
} else {
@@ -548,7 +548,7 @@ function REPLServer(prompt,
548
548
if ( ! self . underscoreAssigned ) {
549
549
self . last = ret ;
550
550
}
551
- self . outputStream . write ( self . writer ( ret ) + '\n' ) ;
551
+ self . outputStream . write ( self . writer ( ret ) + '\r\ n' ) ;
552
552
}
553
553
554
554
// Display prompt again
@@ -578,10 +578,10 @@ function REPLServer(prompt,
578
578
579
579
self . on ( 'SIGCONT' , function ( ) {
580
580
if ( self . editorMode ) {
581
- self . outputStream . write ( `${ self . _initialPrompt } .editor\n` ) ;
581
+ self . outputStream . write ( `${ self . _initialPrompt } .editor\r\ n` ) ;
582
582
self . outputStream . write (
583
- '// Entering editor mode (^D to finish, ^C to cancel)\n' ) ;
584
- self . outputStream . write ( `${ self . bufferedCommand } \n` ) ;
583
+ '// Entering editor mode (^D to finish, ^C to cancel)\r\ n' ) ;
584
+ self . outputStream . write ( `${ self . bufferedCommand } \r\ n` ) ;
585
585
self . prompt ( true ) ;
586
586
} else {
587
587
self . displayPrompt ( true ) ;
@@ -713,7 +713,7 @@ REPLServer.prototype.createContext = function() {
713
713
this . last = value ;
714
714
if ( ! this . underscoreAssigned ) {
715
715
this . underscoreAssigned = true ;
716
- this . outputStream . write ( 'Expression assignment to _ now disabled.\n' ) ;
716
+ this . outputStream . write ( 'Expression assignment to _ now disabled.\r\ n' ) ;
717
717
}
718
718
}
719
719
} ) ;
@@ -762,7 +762,7 @@ function ArrayStream() {
762
762
this . run = function ( data ) {
763
763
var self = this ;
764
764
data . forEach ( function ( line ) {
765
- self . emit ( 'data' , line + '\n' ) ;
765
+ self . emit ( 'data' , line + '\r\ n' ) ;
766
766
} ) ;
767
767
} ;
768
768
}
@@ -1232,7 +1232,7 @@ function defineDefaultCommands(repl) {
1232
1232
this . lineParser . reset ( ) ;
1233
1233
this . bufferedCommand = '' ;
1234
1234
if ( ! this . useGlobal ) {
1235
- this . outputStream . write ( 'Clearing context...\n' ) ;
1235
+ this . outputStream . write ( 'Clearing context...\r\ n' ) ;
1236
1236
this . resetContext ( ) ;
1237
1237
}
1238
1238
this . displayPrompt ( ) ;
@@ -1252,7 +1252,7 @@ function defineDefaultCommands(repl) {
1252
1252
var self = this ;
1253
1253
Object . keys ( this . commands ) . sort ( ) . forEach ( function ( name ) {
1254
1254
var cmd = self . commands [ name ] ;
1255
- self . outputStream . write ( name + '\t' + ( cmd . help || '' ) + '\n' ) ;
1255
+ self . outputStream . write ( name + '\t' + ( cmd . help || '' ) + '\r\ n' ) ;
1256
1256
} ) ;
1257
1257
this . displayPrompt ( ) ;
1258
1258
}
@@ -1262,10 +1262,10 @@ function defineDefaultCommands(repl) {
1262
1262
help : 'Save all evaluated commands in this REPL session to a file' ,
1263
1263
action : function ( file ) {
1264
1264
try {
1265
- fs . writeFileSync ( file , this . lines . join ( '\n' ) + '\n' ) ;
1266
- this . outputStream . write ( 'Session saved to:' + file + '\n' ) ;
1265
+ fs . writeFileSync ( file , this . lines . join ( '\r\ n' ) + '\r \n' ) ;
1266
+ this . outputStream . write ( 'Session saved to:' + file + '\r\ n' ) ;
1267
1267
} catch ( e ) {
1268
- this . outputStream . write ( 'Failed to save:' + file + '\n' ) ;
1268
+ this . outputStream . write ( 'Failed to save:' + file + '\r\ n' ) ;
1269
1269
}
1270
1270
this . displayPrompt ( ) ;
1271
1271
}
@@ -1279,19 +1279,21 @@ function defineDefaultCommands(repl) {
1279
1279
if ( stats && stats . isFile ( ) ) {
1280
1280
var self = this ;
1281
1281
var data = fs . readFileSync ( file , 'utf8' ) ;
1282
- var lines = data . split ( '\n' ) ;
1282
+ // \r\n, \n, or \r followed by something other than \n
1283
+ const lineEnding = / \r ? \n | \r (? ! \n ) / ;
1284
+ var lines = data . split ( lineEnding ) ;
1283
1285
this . displayPrompt ( ) ;
1284
1286
lines . forEach ( function ( line ) {
1285
1287
if ( line ) {
1286
- self . write ( line + '\n' ) ;
1288
+ self . write ( line + '\r\ n' ) ;
1287
1289
}
1288
1290
} ) ;
1289
1291
} else {
1290
1292
this . outputStream . write ( 'Failed to load:' + file +
1291
- ' is not a valid file\n' ) ;
1293
+ ' is not a valid file\r\ n' ) ;
1292
1294
}
1293
1295
} catch ( e ) {
1294
- this . outputStream . write ( 'Failed to load:' + file + '\n' ) ;
1296
+ this . outputStream . write ( 'Failed to load:' + file + '\r\ n' ) ;
1295
1297
}
1296
1298
this . displayPrompt ( ) ;
1297
1299
}
@@ -1304,7 +1306,7 @@ function defineDefaultCommands(repl) {
1304
1306
this . editorMode = true ;
1305
1307
REPLServer . super_ . prototype . setPrompt . call ( this , '' ) ;
1306
1308
this . outputStream . write (
1307
- '// Entering editor mode (^D to finish, ^C to cancel)\n' ) ;
1309
+ '// Entering editor mode (^D to finish, ^C to cancel)\r\ n' ) ;
1308
1310
}
1309
1311
} ) ;
1310
1312
}
0 commit comments