Skip to content

Commit

Permalink
Merge pull request wakatime#164 from codinggirl/patch-1
Browse files Browse the repository at this point in the history
allow proxy config to be empty or removable
  • Loading branch information
alanhamlett authored Sep 29, 2020
2 parents d0cfe84 + 8f98963 commit 5ea523f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/libs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ export class Libs {
}

public static validateProxy(proxy: string): string {
const err =
'Invalid proxy. Valid formats are https://user:pass@host:port or socks5://user:pass@host:port or domain\\user:pass';
if (!proxy) return err;
let re = new RegExp('^((https?|socks5)://)?([^:@]+(:([^:@])+)?@)?[\\w\\.-]+(:\\d+)?$', 'i');
if (proxy.indexOf('\\') > -1) re = new RegExp('^.*\\\\.+$', 'i');
if (!re.test(proxy)) return err;
if (!proxy) return '';
let re;
if (proxy.indexOf('\\') === -1) {
re = new RegExp('^((https?|socks5)://)?([^:@]+(:([^:@])+)?@)?[\\w\\.-]+(:\\d+)?$', 'i');
} else {
re = new RegExp('^.*\\\\.+$', 'i');
}
if (!re.test(proxy)) return 'Invalid proxy. Valid formats are https://user:pass@host:port or socks5://user:pass@host:port or domain\\user:pass';
return '';
}
}

0 comments on commit 5ea523f

Please sign in to comment.