rename mutated hostname and pathname variables to avoid confusion

This commit is contained in:
mzivil 2024-02-02 15:57:34 -05:00
parent db7c4c3d76
commit 7ff02ebe30
1 changed files with 7 additions and 7 deletions

View File

@ -542,21 +542,21 @@ export default {
const urlObj = new URL(ensureProtocol(url))
let { hostname, pathname } = urlObj
hostname = hostname + '(:[0-9]+)?'
let hostnameRegex = hostname + '(:[0-9]+)?'
const parseResult = parse(urlObj.hostname)
if (parseResult?.subdomain?.length) {
const { subdomain } = parseResult
hostname = hostname.replace(subdomain, '(%)?')
hostnameRegex = hostnameRegex.replace(subdomain, '(%)?')
} else {
hostname = `(%.)?${hostname}`
hostnameRegex = `(%.)?${hostnameRegex}`
}
// escape postgres regex meta characters
pathname = pathname.replace(/\+/g, '\\+')
pathname = pathname.replace(/%/g, '\\%')
pathname = pathname.replace(/_/g, '\\_')
let pathnameRegex = pathname.replace(/\+/g, '\\+')
pathnameRegex = pathnameRegex.replace(/%/g, '\\%')
pathnameRegex = pathnameRegex.replace(/_/g, '\\_')
let uriRegex = stripTrailingSlash(hostname + pathname)
let uriRegex = stripTrailingSlash(hostnameRegex + pathnameRegex)
let similar = `(http(s)?://)?${uriRegex}/?`
const whitelist = ['news.ycombinator.com/item', 'bitcointalk.org/index.php']