@@ -93,30 +93,15 @@ export function formatUrl(
93
93
urlString = `${ url } ?${ queryString } ` ;
94
94
}
95
95
96
+ /**
97
+ * Workararound for Safari 14.0
98
+ * @see https://github.com/igorkamyshev/farfetched/issues/528
99
+ */
100
+ const urlArgs = [ urlString , urlBase ] . filter ( Boolean ) as [ string , string ] ;
101
+
96
102
try {
97
- return new URL ( urlString , urlBase ) ;
103
+ return new URL ( ... urlArgs ) ;
98
104
} catch ( e ) {
99
- if ( ! urlBase ) {
100
- try {
101
- /**
102
- * Fallback branch for Safari 14.0
103
- * @see https://github.com/igorkamyshev/farfetched/issues/528
104
- *
105
- * If url is full path, but we're in Safari 14.0, we will have a TypeError for new URL(urlString, undefined)
106
- *
107
- * So we have to manually split url into base and path parts first
108
- */
109
- const { base, path } = splitUrl ( urlString ) ;
110
-
111
- return new URL ( path , base ) ;
112
- } catch ( _e ) {
113
- throw configurationError ( {
114
- reason : 'Invalid URL' ,
115
- validationErrors : [ `"${ urlString } " is not valid URL` ] ,
116
- } ) ;
117
- }
118
- }
119
-
120
105
throw configurationError ( {
121
106
reason : 'Invalid URL' ,
122
107
validationErrors : [ `"${ urlString } " is not valid URL` ] ,
@@ -150,19 +135,3 @@ function clearValue(
150
135
151
136
return value ?? null ;
152
137
}
153
-
154
- /**
155
- * @see https://github.com/igorkamyshev/farfetched/issues/528
156
- */
157
- export function splitUrl ( urlString : string ) : { base : string ; path : string } {
158
- const urlPattern = / ^ ( h t t p s ? : \/ \/ [ ^ \/ ] + ) ( \/ .* ) ? $ / ;
159
- const match = urlString . match ( urlPattern ) ;
160
-
161
- if ( ! match ) {
162
- throw new Error ( `Invalid URL: ${ urlString } ` ) ;
163
- }
164
-
165
- const base = match [ 1 ] ;
166
- const path = match [ 2 ] || '' ;
167
- return { base, path } ;
168
- }
0 commit comments