Skip to content
Snippets Groups Projects
Commit 37844a9b authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

refine url validation, fixes #4021

Closes #4021

Merge request studip/studip!2870
parent cc9daefe
No related branches found
No related tags found
No related merge requests found
......@@ -234,17 +234,16 @@ export default {
this.currentUrlIsValid = this.isValidUrl(this.currentUrl);
},
isValidUrl(urlString) {
const urlPattern = new RegExp(
'^(https?:\\/\\/)?' + // validate protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // validate domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // validate OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // validate port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // validate query string
'(\\#[-a-z\\d_]*)?$',
'i'
); // validate fragment locator
if (!urlString.startsWith('http')) {
urlString = `${location.protocol}//${urlString}`;
}
return !!urlPattern.test(urlString);
try {
const url = new URL(urlString);
return ['http:', 'https:'].includes(url.protocol);
} catch (e) {
return false;
}
},
updateUrl() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment