@@ -688,6 +688,31 @@ describe('input formats', function() {
688688 it ( 'should read base64 strings' , function ( ) { artifax . forEach ( function ( p ) {
689689 X . read ( fs . readFileSync ( p , 'base64' ) , { type : 'base64' } ) ;
690690 } ) ; } ) ;
691+
692+ it ( 'handles base64 within data URI scheme (gh-2762)' , function ( ) {
693+ // Arrange
694+ var fileInBase64 = 'TmFtZXMNCkhhZmV6DQpTYW0NCg==' ;
695+ var fileInBase64WithDataURIScheme = 'data:text/csv;base64,TmFtZXMNCkhhZmV6DQpTYW0NCg==' ;
696+
697+ // Act
698+ var workBookFromRawBase64 = X . read ( fileInBase64 , { type : 'base64' } ) ;
699+ var workBookFromBase64WithinDataURI = X . read ( fileInBase64WithDataURIScheme , { type : 'base64' } ) ;
700+
701+ // Assert
702+ assert . deepStrictEqual ( workBookFromRawBase64 , workBookFromBase64WithinDataURI ) ;
703+ } ) ;
704+ it ( 'handles base64 where data URI has no media type (gh-2762)' , function ( ) {
705+ // Arrange
706+ var fileInBase64 = 'TmFtZXMNCkhhZmV6DQpTYW0NCg==' ;
707+ var fileInBase64WithDataURIScheme = 'data:;base64,TmFtZXMNCkhhZmV6DQpTYW0NCg==' ;
708+
709+ // Act
710+ var workBookFromRawBase64 = X . read ( fileInBase64 , { type : 'base64' } ) ;
711+ var workBookFromBase64WithinDataURI = X . read ( fileInBase64WithDataURIScheme , { type : 'base64' } ) ;
712+
713+ // Assert
714+ assert . deepStrictEqual ( workBookFromRawBase64 , workBookFromBase64WithinDataURI ) ;
715+ } ) ;
691716 if ( typeof Uint8Array !== 'undefined' ) it ( 'should read array' , function ( ) { artifax . forEach ( function ( p ) {
692717 X . read ( fs . readFileSync ( p , 'binary' ) . split ( "" ) . map ( function ( x ) { return x . charCodeAt ( 0 ) ; } ) , { type :'array' } ) ;
693718 } ) ; } ) ;
@@ -1393,7 +1418,7 @@ describe('parse features', function() {
13931418 } ) ;
13941419
13951420 describe ( 'data types formats' , function ( ) { [
1396- [ 'xlsx' , paths . dtfxlsx ] ,
1421+ [ 'xlsx' , paths . dtfxlsx ]
13971422 ] . forEach ( function ( m ) { it ( m [ 0 ] , function ( ) {
13981423 var wb = X . read ( fs . readFileSync ( m [ 1 ] ) , { type : TYPE , cellDates : true } ) ;
13991424 var ws = wb . Sheets [ wb . SheetNames [ 0 ] ] ;
@@ -2109,7 +2134,7 @@ function plaintext_test(wb, raw) {
21092134 var sheet = wb . Sheets [ wb . SheetNames [ 0 ] ] ;
21102135 plaintext_val . forEach ( function ( x ) {
21112136 var cell = get_cell ( sheet , x [ 0 ] ) ;
2112- var tcval = x [ 2 + ( ! ! raw ? 1 : 0 ) ] ;
2137+ var tcval = x [ 2 + ( raw ? 1 : 0 ) ] ;
21132138 var type = raw ? 's' : x [ 1 ] ;
21142139 if ( x . length == 1 ) { if ( cell ) { assert . equal ( cell . t , 'z' ) ; assert . ok ( ! cell . v ) ; } return ; }
21152140 assert . equal ( cell . v , tcval ) ; assert . equal ( cell . t , type ) ;
@@ -2201,8 +2226,8 @@ describe('CSV', function() {
22012226 var aoa = [
22022227 [ "3a" , "3 a" , "3 a-1" ] ,
22032228 [ "3b" , "3 b" , "3 b-1" ] ,
2204- [ "3p" , "3 P" , "3 p-1" ] ,
2205- ]
2229+ [ "3p" , "3 P" , "3 p-1" ]
2230+ ] ;
22062231 var ws = X . read ( aoa . map ( function ( row ) { return row . join ( "," ) ; } ) . join ( "\n" ) , { type : "string" , cellDates : true } ) . Sheets . Sheet1 ;
22072232 for ( var R = 0 ; R < 3 ; ++ R ) {
22082233 assert . equal ( get_cell ( ws , "A" + ( R + 1 ) ) . v , aoa [ R ] [ 0 ] ) ;
0 commit comments