File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -385,11 +385,11 @@ define([
385
385
// carriage return characters
386
386
function fixCarriageReturn ( txt ) {
387
387
txt = txt . replace ( / \r + \n / gm, '\n' ) ; // \r followed by \n --> newline
388
- while ( txt . search ( / \r / g) > - 1 ) {
389
- var base = txt . match ( / ^ . * \r + / m) [ 0 ] . replace ( / \r / , '' ) ;
390
- var insert = txt . match ( / \r + . * $ / m) [ 0 ] . replace ( / \r / , '' ) ;
388
+ while ( txt . search ( / \r [ ^ $ ] / g) > - 1 ) {
389
+ var base = txt . match ( / ^ ( . * ) \r + / m) [ 1 ] ;
390
+ var insert = txt . match ( / \r + ( . * ) $ / m) [ 1 ] ;
391
391
insert = insert + base . slice ( insert . length , base . length ) ;
392
- txt = txt . replace ( / \r + .* $ / m, '\r' ) . replace ( / ^ .* \r + / m, insert ) ;
392
+ txt = txt . replace ( / \r + .* $ / m, '\r' ) . replace ( / ^ .* \r / m, insert ) ;
393
393
}
394
394
return txt ;
395
395
}
Original file line number Diff line number Diff line change @@ -26,6 +26,31 @@ casper.notebook_test(function () {
26
26
27
27
this . test . assertEquals ( result , output , "IPython.utils.fixConsole() handles [0m correctly" ) ;
28
28
29
+ var input = [
30
+ 'hasrn\r\n' ,
31
+ 'hasn\n' ,
32
+ '\n' ,
33
+ 'abcdef\r' ,
34
+ 'hello\n' ,
35
+ 'ab3\r' ,
36
+ 'x2\r\r' ,
37
+ '1\r' ,
38
+ ] . join ( '' ) ;
39
+
40
+ var output = [
41
+ 'hasrn\n' ,
42
+ 'hasn\n' ,
43
+ '\n' ,
44
+ 'hellof\n' ,
45
+ '123\r'
46
+ ] . join ( '' ) ;
47
+
48
+ var result = this . evaluate ( function ( input ) {
49
+ return IPython . utils . fixCarriageReturn ( input ) ;
50
+ } , input ) ;
51
+
52
+ this . test . assertEquals ( result , output , "IPython.utils.fixCarriageReturns works" ) ;
53
+
29
54
this . thenEvaluate ( function ( ) {
30
55
define ( 'nbextensions/a' , [ ] , function ( ) { window . a = true ; } ) ;
31
56
define ( 'nbextensions/c' , [ ] , function ( ) { window . c = true ; } ) ;
You can’t perform that action at this time.
0 commit comments