improve url regex

This commit is contained in:
Eduard Heimbuch
2020-12-03 09:47:41 +01:00
parent 715c76e2f4
commit 11755d3980
2 changed files with 5 additions and 6 deletions

View File

@@ -141,7 +141,6 @@ describe("test path validation", () => {
describe("test url validation", () => {
const invalid = [
"file:///blah/index.html",
"http://",
"http://.",
"http://..",
@@ -158,12 +157,9 @@ describe("test url validation", () => {
"///a",
"///",
"foo.com",
"rdar://1234",
"h://test",
"http:// shouldfail.com",
":// should fail",
"http://foo.bar/foo(bar)baz quux",
"ftps://foo.bar/",
"http://.www.foo.bar/",
"http://.www.foo.bar./"
];
@@ -173,9 +169,12 @@ describe("test url validation", () => {
});
}
const valid = [
"ftps://foo.bar/",
"h://test",
"rdar://1234",
"file:///blah/index.html",
"https://foo.com/blah_blah",
"ssh://foo.com/blah_blah",
"ftp://foo.com/blah_blah",
"https://foo.com/blah_blah/",
"https://foo.com/blah_blah_(wikipedia)",
"https://foo.com/blah_blah_(wikipedia)_(again)",

View File

@@ -50,7 +50,7 @@ export const isPathValid = (path: string) => {
return pathRegex.test(path);
};
const urlRegex = /^(ssh|ftp|https?):\/\/[^\s$.?#].[^\s]*$/;
const urlRegex = /^[A-Za-z0-9]+:\/\/[^\s$.?#].[^\s]*$/;
export const isUrlValid = (url: string) => {
return urlRegex.test(url);