summaryrefslogtreecommitdiff
path: root/public/js
diff options
context:
space:
mode:
authorDavid Mehren2020-10-30 18:40:09 +0100
committerDavid Mehren2020-11-10 20:35:53 +0100
commitbd11faa203800921c0cc89fddc7cd902d2d21c38 (patch)
treedd7d453360707db5e6a8f46e57f52c88b3a96e6d /public/js
parenta160d81fe33044ca8fbb71addd77c40d55b37251 (diff)
Use URL constructor instead of regex to check for valid URL
Fixes #545 Co-authored-by: Yannick Bungers <git@innay.de> Signed-off-by: David Mehren <git@herrmehren.de>
Diffstat (limited to '')
-rw-r--r--public/js/extra.js13
1 files changed, 4 insertions, 9 deletions
diff --git a/public/js/extra.js b/public/js/extra.js
index a6b01a91..0a95b1b1 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -178,16 +178,11 @@ function slugifyWithUTF8 (text) {
}
export function isValidURL (str) {
- const pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
- '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
- '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
- '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
- '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
- '(\\#[-a-z\\d_]*)?$', 'i') // fragment locator
- if (!pattern.test(str)) {
+ try {
+ const url = new URL(str)
+ return ['http:', 'https:'].includes(url.protocol)
+ } catch (e) {
return false
- } else {
- return true
}
}