@@ -688,6 +688,31 @@ describe('input formats', function() {
688
688
it ( 'should read base64 strings' , function ( ) { artifax . forEach ( function ( p ) {
689
689
X . read ( fs . readFileSync ( p , 'base64' ) , { type : 'base64' } ) ;
690
690
} ) ; } ) ;
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
+ } ) ;
691
716
if ( typeof Uint8Array !== 'undefined' ) it ( 'should read array' , function ( ) { artifax . forEach ( function ( p ) {
692
717
X . read ( fs . readFileSync ( p , 'binary' ) . split ( "" ) . map ( function ( x ) { return x . charCodeAt ( 0 ) ; } ) , { type :'array' } ) ;
693
718
} ) ; } ) ;
@@ -1393,7 +1418,7 @@ describe('parse features', function() {
1393
1418
} ) ;
1394
1419
1395
1420
describe ( 'data types formats' , function ( ) { [
1396
- [ 'xlsx' , paths . dtfxlsx ] ,
1421
+ [ 'xlsx' , paths . dtfxlsx ]
1397
1422
] . forEach ( function ( m ) { it ( m [ 0 ] , function ( ) {
1398
1423
var wb = X . read ( fs . readFileSync ( m [ 1 ] ) , { type : TYPE , cellDates : true } ) ;
1399
1424
var ws = wb . Sheets [ wb . SheetNames [ 0 ] ] ;
@@ -2109,7 +2134,7 @@ function plaintext_test(wb, raw) {
2109
2134
var sheet = wb . Sheets [ wb . SheetNames [ 0 ] ] ;
2110
2135
plaintext_val . forEach ( function ( x ) {
2111
2136
var cell = get_cell ( sheet , x [ 0 ] ) ;
2112
- var tcval = x [ 2 + ( ! ! raw ? 1 : 0 ) ] ;
2137
+ var tcval = x [ 2 + ( raw ? 1 : 0 ) ] ;
2113
2138
var type = raw ? 's' : x [ 1 ] ;
2114
2139
if ( x . length == 1 ) { if ( cell ) { assert . equal ( cell . t , 'z' ) ; assert . ok ( ! cell . v ) ; } return ; }
2115
2140
assert . equal ( cell . v , tcval ) ; assert . equal ( cell . t , type ) ;
@@ -2201,8 +2226,8 @@ describe('CSV', function() {
2201
2226
var aoa = [
2202
2227
[ "3a" , "3 a" , "3 a-1" ] ,
2203
2228
[ "3b" , "3 b" , "3 b-1" ] ,
2204
- [ "3p" , "3 P" , "3 p-1" ] ,
2205
- ]
2229
+ [ "3p" , "3 P" , "3 p-1" ]
2230
+ ] ;
2206
2231
var ws = X . read ( aoa . map ( function ( row ) { return row . join ( "," ) ; } ) . join ( "\n" ) , { type : "string" , cellDates : true } ) . Sheets . Sheet1 ;
2207
2232
for ( var R = 0 ; R < 3 ; ++ R ) {
2208
2233
assert . equal ( get_cell ( ws , "A" + ( R + 1 ) ) . v , aoa [ R ] [ 0 ] ) ;
0 commit comments