Skip to content

Commit

Permalink
Block aggregator websites
Browse files Browse the repository at this point in the history
  • Loading branch information
pietervdvn committed Aug 23, 2024
1 parent 3b8cb7d commit 0d22af6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
36 changes: 24 additions & 12 deletions src/UI/InputElement/Validators/UrlValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down

0 comments on commit 0d22af6

Please sign in to comment.