@@ -19,9 +19,9 @@ function isUrl (path) {
1919}
2020
2121function getUrl ( currentUrl , path ) {
22- var pathObject = url . parse ( path ) ;
22+ const pathObject = url . parse ( path ) ;
2323 if ( isUrl ( path ) && ! pathObject . protocol ) {
24- var urlObject = url . parse ( currentUrl ) ;
24+ const urlObject = url . parse ( currentUrl ) ;
2525 pathObject . protocol = urlObject . protocol ;
2626 path = url . format ( pathObject ) ;
2727 }
@@ -33,8 +33,8 @@ function getUnixPath (filepath) {
3333}
3434
3535function getRelativePath ( path1 , path2 ) {
36- var dirname = path . dirname ( path1 ) ;
37- var relativePath = path . relative ( dirname , path2 ) ;
36+ const dirname = path . dirname ( path1 ) ;
37+ const relativePath = path . relative ( dirname , path2 ) ;
3838 return getUnixPath ( relativePath ) ;
3939}
4040
@@ -45,8 +45,12 @@ function getRelativePath (path1, path2) {
4545 * @returns {string } decoded pathname
4646 */
4747function getPathnameFromUrl ( u ) {
48- var pathname = url . parse ( u ) . pathname ;
49- return decodeURI ( pathname ) ;
48+ const pathname = url . parse ( u ) . pathname ;
49+ try {
50+ return decodeURI ( pathname ) ;
51+ } catch ( e ) {
52+ return pathname ;
53+ }
5054}
5155
5256/**
@@ -96,8 +100,8 @@ function getFilenameExtension (filepath) {
96100
97101function shortenFilename ( filename ) {
98102 if ( filename . length >= MAX_FILENAME_LENGTH ) {
99- var shortFilename = filename . substring ( 0 , 20 ) + getFilenameExtension ( filename ) ;
100- logger . debug ( ' shorten filename: ' + filename + ' -> ' + shortFilename ) ;
103+ const shortFilename = filename . substring ( 0 , 20 ) + getFilenameExtension ( filename ) ;
104+ logger . debug ( `[utils] shorten filename: ${ filename } -> ${ shortFilename } ` ) ;
101105 return shortFilename ;
102106 }
103107 return filename ;
@@ -110,15 +114,19 @@ function waitAllFulfilled (promises) {
110114}
111115
112116function normalizeUrl ( u , opts ) {
113- return normalize ( u , extend ( { removeTrailingSlash : false } , opts ) ) ;
117+ try {
118+ return normalize ( u , extend ( { removeTrailingSlash : false } , opts ) ) ;
119+ } catch ( e ) {
120+ return u ;
121+ }
114122}
115123
116124function urlsEqual ( url1 , url2 ) {
117125 return normalizeUrl ( url1 ) === normalizeUrl ( url2 ) ;
118126}
119127
120128function isUriSchemaSupported ( path ) {
121- var protocol = url . parse ( path ) . protocol ;
129+ const protocol = url . parse ( path ) . protocol ;
122130 return ! protocol || protocol && isUrl ( path ) ;
123131}
124132
@@ -127,7 +135,7 @@ function getTypeByMime (mimeType) {
127135}
128136
129137function getTypeByFilename ( filename ) {
130- var ext = getFilenameExtension ( filename ) ;
138+ const ext = getFilenameExtension ( filename ) ;
131139 return typeByExt [ ext ] ;
132140}
133141
0 commit comments