@@ -9,8 +9,7 @@ var Base64 = (function make_b64(){
9
9
return {
10
10
encode : function ( input /*:string*/ ) /*:string*/ {
11
11
var o = "" ;
12
- var c1 /*:number*/ , c2 /*:number*/ , c3 /*:number*/ ;
13
- var e1 /*:number*/ , e2 /*:number*/ , e3 /*:number*/ , e4 /*:number*/ ;
12
+ var c1 = 0 , c2 = 0 , c3 = 0 , e1 = 0 , e2 = 0 , e3 = 0 , e4 = 0 ;
14
13
for ( var i = 0 ; i < input . length ; ) {
15
14
c1 = input . charCodeAt ( i ++ ) ;
16
15
e1 = ( c1 >> 2 ) ;
@@ -29,9 +28,7 @@ var Base64 = (function make_b64(){
29
28
} ,
30
29
decode : function b64_decode ( input /*:string*/ ) /*:string*/ {
31
30
var o = "" ;
32
- var c1 /*:number*/ , c2 /*:number*/ , c3 /*:number*/ ;
33
- var e1 /*:number*/ , e2 /*:number*/ , e3 /*:number*/ , e4 /*:number*/ ;
34
- // eslint-disable-next-line no-useless-escape
31
+ var c1 = 0 , c2 = 0 , c3 = 0 , e1 = 0 , e2 = 0 , e3 = 0 , e4 = 0 ;
35
32
input = input . replace ( / [ ^ \w \+ \/ \= ] / g, "" ) ;
36
33
for ( var i = 0 ; i < input . length ; ) {
37
34
e1 = map . indexOf ( input . charAt ( i ++ ) ) ;
@@ -177,10 +174,10 @@ type SectorList = {
177
174
}
178
175
type CFBFiles = {[n:string]:CFBEntry};
179
176
*/
180
- /* [MS-CFB] v20130118 */
177
+ /* [MS-CFB] v20171201 */
181
178
var CFB = ( function _CFB ( ) {
182
179
var exports /*:CFBModule*/ = /*::(*/ { } /*:: :any)*/ ;
183
- exports . version = '1.0.3 ' ;
180
+ exports . version = '1.0.5 ' ;
184
181
/* [MS-CFB] 2.6.4 */
185
182
function namecmp ( l /*:string*/ , r /*:string*/ ) /*:number*/ {
186
183
var L = l . split ( "/" ) , R = r . split ( "/" ) ;
@@ -204,6 +201,7 @@ function filename(p/*:string*/)/*:string*/ {
204
201
var fs /*:: = require('fs'); */ ;
205
202
function get_fs ( ) { return fs || ( fs = require ( 'fs' ) ) ; }
206
203
function parse ( file /*:RawBytes*/ , options /*:CFBReadOpts*/ ) /*:CFBContainer*/ {
204
+ if ( file . length < 512 ) throw new Error ( "CFB file size " + file . length + " < 512" ) ;
207
205
var mver = 3 ;
208
206
var ssz = 512 ;
209
207
var nmfs = 0 ; // number of mini FAT sectors
@@ -360,7 +358,7 @@ function build_full_paths(FI/*:CFBFileIndex*/, FP/*:Array<string>*/, Paths/*:Arr
360
358
if ( L !== - 1 ) { dad [ L ] = dad [ i ] ; q . push ( L ) ; }
361
359
if ( R !== - 1 ) { dad [ R ] = dad [ i ] ; q . push ( R ) ; }
362
360
}
363
- for ( i = 1 ; i !== pl ; ++ i ) if ( dad [ i ] === i ) {
361
+ for ( i = 1 ; i < pl ; ++ i ) if ( dad [ i ] === i ) {
364
362
if ( R !== - 1 /*NOSTREAM*/ && dad [ R ] !== R ) dad [ i ] = dad [ R ] ;
365
363
else if ( L !== - 1 && dad [ L ] !== L ) dad [ i ] = dad [ L ] ;
366
364
}
@@ -752,7 +750,6 @@ function _write(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes*/ {
752
750
}
753
751
/* [MS-CFB] 2.6.4 (Unicode 3.0.1 case conversion) */
754
752
function find ( cfb /*:CFBContainer*/ , path /*:string*/ ) /*:?CFBEntry*/ {
755
- //return cfb.find(path);
756
753
var UCFullPaths /*:Array<string>*/ = cfb . FullPaths . map ( function ( x ) { return x . toUpperCase ( ) ; } ) ;
757
754
var UCPaths /*:Array<string>*/ = UCFullPaths . map ( function ( x ) { var y = x . split ( "/" ) ; return y [ y . length - ( x . slice ( - 1 ) == "/" ? 2 : 1 ) ] ; } ) ;
758
755
var k /*:boolean*/ = false ;
@@ -762,10 +759,12 @@ function find(cfb/*:CFBContainer*/, path/*:string*/)/*:?CFBEntry*/ {
762
759
var w /*:number*/ = k === true ? UCFullPaths . indexOf ( UCPath ) : UCPaths . indexOf ( UCPath ) ;
763
760
if ( w !== - 1 ) return cfb . FileIndex [ w ] ;
764
761
765
- UCPath = UCPath . replace ( chr0 , '' ) . replace ( chr1 , '!' ) ;
762
+ var m = ! UCPath . match ( chr1 ) ;
763
+ UCPath = UCPath . replace ( chr0 , '' ) ;
764
+ if ( m ) UCPath = UCPath . replace ( chr1 , '!' ) ;
766
765
for ( w = 0 ; w < UCFullPaths . length ; ++ w ) {
767
- if ( UCFullPaths [ w ] . replace ( chr0 , '' ) . replace ( chr1 , '! ') == UCPath ) return cfb . FileIndex [ w ] ;
768
- if ( UCPaths [ w ] . replace ( chr0 , '' ) . replace ( chr1 , '! ') == UCPath ) return cfb . FileIndex [ w ] ;
766
+ if ( ( m ? UCFullPaths [ w ] . replace ( chr1 , '!' ) : UCFullPaths [ w ] ) . replace ( chr0 , ' ') == UCPath ) return cfb . FileIndex [ w ] ;
767
+ if ( ( m ? UCPaths [ w ] . replace ( chr1 , '!' ) : UCPaths [ w ] ) . replace ( chr0 , ' ') == UCPath ) return cfb . FileIndex [ w ] ;
769
768
}
770
769
return null ;
771
770
}
0 commit comments