File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -92,13 +92,15 @@ const staticify = (root, options) => {
9292
9393 const fileName = path . basename ( p ) ;
9494 const fileNameParts = fileName . split ( '.' ) ;
95+ const fileNameHashPosition = fileNameParts . length - 2 ;
96+ const fileNameHash = fileNameParts [ fileNameHashPosition ] ;
9597 const re = new RegExp ( `^[0-9a-f]{${ HASH_LEN } }$` , 'i' ) ;
98+ const reResult = re . exec ( fileNameHash ) ;
9699
97- if ( fileNameParts . length >= 3 &&
98- fileNameParts [ fileNameParts . length - 2 ] . length === HASH_LEN &&
99- re . exec ( fileNameParts [ fileNameParts . length - 2 ] ) [ 0 ] === fileNameParts [ fileNameParts . length - 2 ]
100+ if ( fileNameParts . length >= 3 && fileNameHash . length === HASH_LEN &&
101+ ( reResult && reResult [ 0 ] === fileNameHash )
100102 ) {
101- const stripped = fileNameParts . slice ( 0 , fileNameParts . length - 2 ) ;
103+ const stripped = fileNameParts . slice ( 0 , fileNameHashPosition ) ;
102104
103105 stripped . push ( fileNameParts [ fileNameParts . length - 1 ] ) ;
104106
Original file line number Diff line number Diff line change @@ -32,10 +32,18 @@ describe('.stripVersion', () => {
3232 staticify ( ROOT ) . stripVersion ( path . normalize ( '/script.js' ) ) . should . equal ( path . normalize ( '/script.js' ) ) ;
3333 } ) ;
3434
35+ it ( 'should not fail when the path contains a 7 character string that is not a hash' , ( ) => {
36+ staticify ( ROOT ) . stripVersion ( path . normalize ( '/script.abcdefg.html' ) ) . should . equal ( path . normalize ( '/script.abcdefg.html' ) ) ;
37+ } ) ;
38+
3539 it ( 'should strip the (long) hash from a path when necessary' , ( ) => {
3640 staticify ( ROOT , { shortHash : false } ) . stripVersion ( path . normalize ( '/script.4e2502b01a4c92b0a51b1a5a3271eab6.js' ) ) . should . equal ( path . normalize ( '/script.js' ) ) ;
3741 staticify ( ROOT , { shortHash : false } ) . stripVersion ( path . normalize ( '/script.js' ) ) . should . equal ( path . normalize ( '/script.js' ) ) ;
3842 } ) ;
43+
44+ it ( 'should not fail when the path contains a 32 character string that is not a hash' , ( ) => {
45+ staticify ( ROOT ) . stripVersion ( path . normalize ( '/script.abcdefgabcdefgabcdefgabcdefgabcd.html' ) ) . should . equal ( path . normalize ( '/script.abcdefgabcdefgabcdefgabcdefgabcd.html' ) ) ;
46+ } ) ;
3947} ) ;
4048
4149describe ( '.getVersionedPath' , ( ) => {
You can’t perform that action at this time.
0 commit comments