@@ -949,8 +949,7 @@ function getCurrentScriptUrl(moduleId) {
949
949
const reg = new RegExp ( `${ filename } \\.js$` , 'g' ) ;
950
950
951
951
return normalizeUrl (
952
- src . replace ( reg , `${ mapRule . replace ( / { f i l e N a m e } / g, filename ) } .css` ) ,
953
- { stripWWW : false }
952
+ src . replace ( reg , `${ mapRule . replace ( / { f i l e N a m e } / g, filename ) } .css` )
954
953
) ;
955
954
} ) ;
956
955
} ;
@@ -1114,35 +1113,11 @@ module.exports = function (moduleId, options) {
1114
1113
1115
1114
/* eslint-disable */
1116
1115
1117
- function testParameter ( name , filters ) {
1118
- return filters . some ( function ( filter ) {
1119
- return filter instanceof RegExp ? filter . test ( name ) : filter === name ;
1120
- } ) ;
1121
- }
1122
-
1123
- module . exports = function ( urlString , options ) {
1124
- var normalizeOptions = Object . assign (
1125
- { } ,
1126
- {
1127
- defaultProtocol : 'http:' ,
1128
- normalizeProtocol : true ,
1129
- forceHttp : false ,
1130
- forceHttps : false ,
1131
- stripAuthentication : true ,
1132
- stripHash : false ,
1133
- stripWWW : true ,
1134
- removeQueryParameters : [ / ^ u t m _ \w + / i] ,
1135
- removeTrailingSlash : true ,
1136
- removeSingleSlash : true ,
1137
- removeDirectoryIndex : false ,
1138
- sortQueryParameters : true ,
1139
- } ,
1140
- options
1141
- ) ;
1116
+ module . exports = function ( urlString ) {
1117
+ var defaultProtocol = 'http:' ;
1142
1118
1143
1119
urlString = urlString . trim ( ) ;
1144
1120
1145
- // Data URL
1146
1121
if ( / ^ d a t a : / i. test ( urlString ) ) {
1147
1122
return urlString ;
1148
1123
}
@@ -1151,103 +1126,36 @@ module.exports = function (urlString, options) {
1151
1126
urlString . length > 2 && urlString [ 0 ] === '/' && urlString [ 1 ] === '/' ;
1152
1127
var isRelativeUrl = ! hasRelativeProtocol && / ^ \. * \/ / . test ( urlString ) ;
1153
1128
1154
- // Prepend protocol
1155
1129
if ( ! isRelativeUrl ) {
1156
- // eslint-disable-next-line no-param-reassign
1157
- urlString = urlString . replace (
1158
- / ^ (? ! (?: \w + : ) ? \/ \/ ) | ^ \/ \/ / ,
1159
- normalizeOptions . defaultProtocol
1160
- ) ;
1130
+ urlString = urlString . replace ( / ^ (? ! (?: \w + : ) ? \/ \/ ) | ^ \/ \/ / , defaultProtocol ) ;
1161
1131
}
1162
1132
1163
1133
var urlObj = new URL ( urlString ) ;
1164
1134
1165
- // Remove auth
1166
- if ( normalizeOptions . stripAuthentication ) {
1167
- urlObj . username = '' ;
1168
- urlObj . password = '' ;
1169
- }
1170
-
1171
- // Remove hash
1172
- if ( normalizeOptions . stripHash ) {
1173
- urlObj . hash = '' ;
1174
- }
1135
+ var keepTrailingSlash = false ;
1175
1136
1176
1137
// Remove duplicate slashes if not preceded by a protocol
1177
1138
if ( urlObj . pathname ) {
1178
1139
urlObj . pathname = urlObj . pathname . replace (
1179
1140
/ (?< ! \b (?: [ a - z ] [ a - z \d + \- . ] { 1 , 50 } : ) ) \/ { 2 , } / g,
1180
1141
'/'
1181
1142
) ;
1182
- }
1183
1143
1184
- // Decode URI octets
1185
- if ( urlObj . pathname ) {
1186
- try {
1187
- urlObj . pathname = decodeURI ( urlObj . pathname ) ;
1188
- // eslint-disable-next-line no-empty
1189
- } catch ( _ ) { }
1144
+ keepTrailingSlash = / \/ $ / i. test ( urlString ) && / \/ $ / i. test ( urlObj . pathname ) ;
1190
1145
}
1191
1146
1192
1147
if ( urlObj . hostname ) {
1193
- // Remove trailing dot
1194
1148
urlObj . hostname = urlObj . hostname . replace ( / \. $ / , '' ) ;
1195
-
1196
- // Remove `www.`
1197
- if (
1198
- normalizeOptions . stripWWW &&
1199
- / ^ w w w \. (? ! w w w \. ) (?: [ a - z \- \d ] { 1 , 63 } ) \. (?: [ a - z . \- \d ] { 2 , 63 } ) $ / . test (
1200
- urlObj . hostname
1201
- )
1202
- ) {
1203
- urlObj . hostname = urlObj . hostname . replace ( / ^ w w w \. / , '' ) ;
1204
- }
1205
1149
}
1206
1150
1207
- // Remove query unwanted parameters
1208
- if ( Array . isArray ( normalizeOptions . removeQueryParameters ) ) {
1209
- for ( var key in Array . from ( urlObj . searchParams . keys ( ) ) ) {
1210
- if ( testParameter ( key , normalizeOptions . removeQueryParameters ) ) {
1211
- urlObj . searchParams . delete ( key ) ;
1212
- }
1213
- }
1214
- }
1215
-
1216
- // Sort query parameters
1217
- if ( normalizeOptions . sortQueryParameters ) {
1218
- urlObj . searchParams . sort ( ) ;
1219
- }
1220
-
1221
- if ( normalizeOptions . removeTrailingSlash ) {
1222
- urlObj . pathname = urlObj . pathname . replace ( / \/ $ / , '' ) ;
1223
- }
1224
-
1225
- var oldUrlString = urlString ;
1226
-
1227
1151
// Take advantage of many of the Node `url` normalizations
1228
1152
urlString = urlObj . toString ( ) ;
1229
1153
1230
- if (
1231
- ! normalizeOptions . removeSingleSlash &&
1232
- urlObj . pathname === '/' &&
1233
- oldUrlString . indexOf ( '/' ) !== oldUrlString . length - 1 &&
1234
- urlObj . hash === ''
1235
- ) {
1236
- urlString = urlString . replace ( / \/ $ / , '' ) ;
1237
- }
1238
-
1239
- // Remove ending `/` unless removeSingleSlash is false
1240
- if (
1241
- ( normalizeOptions . removeTrailingSlash || urlObj . pathname === '/' ) &&
1242
- urlObj . hash === '' &&
1243
- normalizeOptions . removeSingleSlash
1244
- ) {
1154
+ if ( ! keepTrailingSlash && urlObj . hash === '' ) {
1245
1155
urlString = urlString . replace ( / \/ $ / , '' ) ;
1246
1156
}
1247
1157
1248
- // Restore relative protocol, if applicable
1249
- if ( hasRelativeProtocol && ! normalizeOptions . normalizeProtocol ) {
1250
- // eslint-disable-next-line no-param-reassign
1158
+ if ( hasRelativeProtocol ) {
1251
1159
urlString = urlString . replace ( / ^ h t t p : \/ \/ / , '//' ) ;
1252
1160
}
1253
1161
0 commit comments