diff --git a/package.json b/package.json index 86ef915faa..ad7d01f140 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mapcomplete", - "version": "0.45.3", + "version": "0.45.4", "repository": "https://github.com/pietervdvn/MapComplete", "description": "A small website to edit OSM easily", "bugs": "https://github.com/pietervdvn/MapComplete/issues", diff --git a/src/UI/InputElement/Validators/UrlValidator.ts b/src/UI/InputElement/Validators/UrlValidator.ts index 6733792592..148562f42e 100644 --- a/src/UI/InputElement/Validators/UrlValidator.ts +++ b/src/UI/InputElement/Validators/UrlValidator.ts @@ -12,6 +12,7 @@ export default class UrlValidator extends Validator { "tripadvisor.com", "tripadvisor.co.uk", "tripadvisor.com.au", + "katestravelexperience.eu" ]) constructor(name?: string, explanation?: string, forceHttps?: boolean) { @@ -88,22 +89,24 @@ export default class UrlValidator extends Validator { * */ getFeedback(s: string, getCountry?: () => string): Translation | undefined { + try{ + const url = new URL(s) + let host = url.host.toLowerCase() + if (host.startsWith("www.")) { + host = host.slice(4) + } + if (UrlValidator.aggregatorWebsites.has(host)) { + return Translations.t.validation.url.aggregator.Subs({ host }) + } + }catch (e) { + // pass + } const upstream = super.getFeedback(s, getCountry) if (upstream) { return upstream } - /* - Upstream calls 'isValid', which checks if it is an actual URL. - If we reach this point, we can safely assume 'new URL' will work - */ - const url = new URL(s) - let host = url.host.toLowerCase() - if (host.startsWith("www.")) { - host = host.slice(4) - } - if (UrlValidator.aggregatorWebsites.has(host)) { - return Translations.t.validation.url.aggregator.Subs({ host }) - } + + return undefined } @@ -118,6 +121,15 @@ export default class UrlValidator extends Validator { } const url = new URL(str) const dotIndex = url.host.indexOf(".") + + let host = url.host.toLowerCase() + if (host.startsWith("www.")) { + host = host.slice(4) + } + if (UrlValidator.aggregatorWebsites.has(host)) { + return false + } + return dotIndex > 0 && url.host[url.host.length - 1] !== "." } catch (e) { return false