File tree 2 files changed +18
-6
lines changed
2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -7,11 +7,17 @@ interface ValidURLCheckResult {
7
7
8
8
export function isValidURL ( str : string ) : ValidURLCheckResult {
9
9
try {
10
- if ( ! str . startsWith ( 'https://' ) && ! str . startsWith ( 'http://' ) ) {
11
- str = 'https://' + str ;
12
- }
13
10
const parsedUrl = new URL ( str ) ;
14
11
const regex = / ^ ( [ a - z A - Z 0 - 9 - _ .: ] + ) + $ / ;
12
+
13
+ if ( parsedUrl . protocol !== 'http:' && parsedUrl . protocol !== 'https:'
14
+ && parsedUrl . protocol !== 'ws:' && parsedUrl . protocol !== 'wss:' ) {
15
+ return {
16
+ isValid : false ,
17
+ finalURL : str
18
+ } ;
19
+ }
20
+
15
21
return {
16
22
isValid : regex . test ( parsedUrl . host ) ,
17
23
finalURL : str
Original file line number Diff line number Diff line change @@ -313,11 +313,17 @@ interface ValidURLCheckResult {
313
313
314
314
export function isValidURL ( str : string ) : ValidURLCheckResult {
315
315
try {
316
- // if (!str.startsWith('https://') && !str.startsWith('http://')) {
317
- // str = 'https://' + str;
318
- // }
319
316
const parsedUrl = new URL ( str ) ;
320
317
const regex = / ^ ( [ a - z A - Z 0 - 9 - _ .: ] + ) + $ / ;
318
+
319
+ if ( parsedUrl . protocol !== 'http:' && parsedUrl . protocol !== 'https:'
320
+ && parsedUrl . protocol !== 'ws:' && parsedUrl . protocol !== 'wss:' ) {
321
+ return {
322
+ isValid : false ,
323
+ finalURL : str
324
+ } ;
325
+ }
326
+
321
327
return {
322
328
isValid : regex . test ( parsedUrl . host ) ,
323
329
finalURL : str
You can’t perform that action at this time.
0 commit comments