File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -231,6 +231,13 @@ func GetMediaExtensions() []string {
231
231
232
232
// RemoveDefaultPort removes the default port from a URL based on its scheme.
233
233
func RemoveDefaultPort (urlStr string ) (string , error ) {
234
+ isTempScheme := false
235
+
236
+ if ! strings .Contains (urlStr , "://" ) {
237
+ urlStr = "temp://" + urlStr
238
+ isTempScheme = true
239
+ }
240
+
234
241
u , err := url .Parse (urlStr )
235
242
if err != nil {
236
243
return "" , fmt .Errorf ("invalid URL: %w" , err )
@@ -265,6 +272,8 @@ func RemoveDefaultPort(urlStr string) (string, error) {
265
272
defaultPort = "443"
266
273
case "ftp" :
267
274
defaultPort = "21"
275
+ case "temp" :
276
+ defaultPort = ""
268
277
default :
269
278
return u .String (), nil
270
279
}
@@ -273,5 +282,10 @@ func RemoveDefaultPort(urlStr string) (string, error) {
273
282
u .Host = host
274
283
}
275
284
276
- return u .String (), nil
285
+ finalURL := u .String ()
286
+ if isTempScheme {
287
+ finalURL = strings .TrimPrefix (finalURL , "temp://" )
288
+ }
289
+
290
+ return finalURL , nil
277
291
}
You can’t perform that action at this time.
0 commit comments