-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Address regex url validation bug (#1586)
Resolves [1197](https://issues.redhat.com/browse/MTA-1197) Signed-off-by: ibolton336 <[email protected]>
- Loading branch information
1 parent
836d531
commit 5b9531f
Showing
2 changed files
with
62 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,49 +98,67 @@ describe("utils", () => { | |
expect(result).toBe("myKey"); | ||
}); | ||
|
||
//URL Regex tests | ||
it("Regex should validate git URLs", () => { | ||
const testGitURLs: string[] = [ | ||
"[email protected]:konveyor/tackle2-ui", | ||
"http://[email protected]:konveyor/tackle2-ui", | ||
]; | ||
|
||
for (const url of testGitURLs) { | ||
const gitTestResult = gitUrlRegex.test(url); | ||
expect(gitTestResult).toBe(true); | ||
} | ||
}); | ||
|
||
it("Regex should validate standard URLs", () => { | ||
const testStandardURLs: string[] = [ | ||
"http://www.foo.bar", | ||
"www.foo.bar", | ||
"https://www.github.com/ibolton336/tackle-testapp.git", | ||
]; | ||
|
||
for (const url of testStandardURLs) { | ||
const standardTestResult = standardURLRegex.test(url); | ||
expect(standardTestResult).toBe(true); | ||
} | ||
}); | ||
|
||
it("Regex should fail when validating broken standard URLs", () => { | ||
const testBrokenURLs: string[] = [ | ||
"", | ||
" http://www.foo.bar ", | ||
" http://www.foo", | ||
" http://wrong", | ||
"wwwfoo.bar", | ||
"foo.bar", | ||
"www.foo.b", | ||
"foo.ba", | ||
"[email protected]:konveyor/tackle2-ui", | ||
]; | ||
|
||
for (const url of testBrokenURLs) { | ||
const testResult = standardURLRegex.test(url); | ||
expect(testResult).toBe(false); | ||
} | ||
describe("URL Regex tests", () => { | ||
// Define your regex patterns here | ||
|
||
it("Regex should validate git URLs", () => { | ||
const testGitURLs = [ | ||
"[email protected]:konveyor/tackle2-ui.git", | ||
"http://github.com/konveyor/tackle2-ui.git", | ||
]; | ||
|
||
for (const url of testGitURLs) { | ||
expect(gitUrlRegex.test(url)).toBe(true); | ||
} | ||
}); | ||
|
||
it("Regex should fail when validating incorrect git URLs", () => { | ||
const testIncorrectGitURLs = [ | ||
"https://", | ||
"git@", | ||
"http://github.com/konveyor", | ||
]; | ||
|
||
for (const url of testIncorrectGitURLs) { | ||
const result = gitUrlRegex.test(url); | ||
console.log(`Testing URL: ${url}, Result: ${result}`); | ||
|
||
expect(result).toBe(false); | ||
} | ||
}); | ||
|
||
it("Regex should validate standard URLs", () => { | ||
const testStandardURLs = [ | ||
"http://www.foo.bar", | ||
"www.foo.bar", | ||
"https://www.github.com/ibolton336/tackle-testapp.git", | ||
]; | ||
|
||
for (const url of testStandardURLs) { | ||
expect(standardURLRegex.test(url)).toBe(true); | ||
} | ||
}); | ||
|
||
it("Regex should fail when validating broken standard URLs", () => { | ||
const testBrokenURLs = [ | ||
"", | ||
"http://", | ||
"https://", | ||
"http:", | ||
"http://www.foo", | ||
"http://wrong", | ||
"wwwfoo.bar", | ||
"foo.bar", | ||
"www.foo.b", | ||
]; | ||
|
||
for (const url of testBrokenURLs) { | ||
const result = standardURLRegex.test(url); | ||
console.log(`Testing URL: ${url}, Result: ${result}`); | ||
|
||
expect(result).toBe(false); | ||
} | ||
}); | ||
}); | ||
|
||
it("URL should match the same multiple times in a row", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters