@@ -136,6 +136,22 @@ class Server {
136
136
return compilers . map ( ( compiler ) => compiler . options ) ;
137
137
}
138
138
139
+ // eslint-disable-next-line class-methods-use-this
140
+ isAbsoluteURL ( URL ) {
141
+ if ( typeof URL !== "string" ) {
142
+ throw new TypeError ( `Expected a \`string\`, got \`${ typeof URL } \`` ) ;
143
+ }
144
+
145
+ // Don't match Windows paths `c:\`
146
+ if ( / ^ [ a - z A - Z ] : \\ / . test ( URL ) ) {
147
+ return false ;
148
+ }
149
+
150
+ // Scheme: https://tools.ietf.org/html/rfc3986#section-3.1
151
+ // Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
152
+ return / ^ [ a - z A - Z ] [ a - z A - Z \d + \- . ] * : / . test ( URL ) ;
153
+ }
154
+
139
155
// eslint-disable-next-line class-methods-use-this
140
156
normalizeOptions ( options ) {
141
157
// TODO: improve this to not use .find for compiler watchOptions
@@ -532,10 +548,8 @@ class Server {
532
548
}
533
549
534
550
if ( options . static ) {
535
- const isAbsoluteUrl = require ( "is-absolute-url" ) ;
536
-
537
551
options . static . forEach ( ( staticOption ) => {
538
- if ( isAbsoluteUrl ( staticOption . directory ) ) {
552
+ if ( this . isAbsoluteURL ( staticOption . directory ) ) {
539
553
throw new Error ( "Using a URL as static.directory is not supported" ) ;
540
554
}
541
555
@@ -1202,7 +1216,6 @@ class Server {
1202
1216
}
1203
1217
1204
1218
openBrowser ( defaultOpenTarget ) {
1205
- const isAbsoluteUrl = require ( "is-absolute-url" ) ;
1206
1219
const open = require ( "open" ) ;
1207
1220
1208
1221
Promise . all (
@@ -1212,7 +1225,7 @@ class Server {
1212
1225
if ( item . target === "<url>" ) {
1213
1226
openTarget = defaultOpenTarget ;
1214
1227
} else {
1215
- openTarget = isAbsoluteUrl ( item . target )
1228
+ openTarget = this . isAbsoluteURL ( item . target )
1216
1229
? item . target
1217
1230
: new URL ( item . target , defaultOpenTarget ) . toString ( ) ;
1218
1231
}
0 commit comments