Skip to content

Commit 7ca48bf

Browse files
Remove http on top of the url and check it's protocol
1 parent a00a58b commit 7ca48bf

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

electron/utils.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ interface ValidURLCheckResult {
77

88
export function isValidURL(str: string): ValidURLCheckResult {
99
try {
10-
if (!str.startsWith('https://') && !str.startsWith('http://')) {
11-
str = 'https://' + str;
12-
}
1310
const parsedUrl = new URL(str);
1411
const regex = /^([a-zA-Z0-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+
1521
return {
1622
isValid: regex.test(parsedUrl.host),
1723
finalURL: str

src/utils/utils.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,17 @@ interface ValidURLCheckResult {
313313

314314
export function isValidURL(str: string): ValidURLCheckResult {
315315
try {
316-
// if (!str.startsWith('https://') && !str.startsWith('http://')) {
317-
// str = 'https://' + str;
318-
// }
319316
const parsedUrl = new URL(str);
320317
const regex = /^([a-zA-Z0-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+
321327
return {
322328
isValid: regex.test(parsedUrl.host),
323329
finalURL: str

0 commit comments

Comments
 (0)