fix(clean_url): encode ^

this is unrelated to address separator of adblock filter syntax
https://adblockplus.org/filter-cheatsheet#blocking1
which does not need to be escaped
uBO can handle this pattern just fine
||example.com/so%5Emany?ca^r=e^t^$all

query string does not need to percent-encode ^,
only pathname
This commit is contained in:
MDLeom 2025-03-19 10:22:34 +00:00
parent fd8184a806
commit 62c754fe23
No known key found for this signature in database
GPG Key ID: 32D3E28E96A695E8
1 changed files with 5 additions and 1 deletions

View File

@ -30,7 +30,11 @@ for await (const line of createInterface({ input: process.stdin, terminal: false
url = new URL(url.searchParams.get('url'))
}
const outUrl = `${url.host.replace(/^www\./, '')}${url.pathname}${url.search}`
url.host = url.host.replace(/^www\./, '')
// nodejs does not percent-encode ^ yet
// https://github.com/nodejs/node/issues/57313
url.pathname = url.pathname.replaceAll('^', encodeURI('^'))
const outUrl = `${url.host}${url.pathname}${url.search}`
// remove trailing slash from domain except path #43
.replace(/(^[^/]*)\/+$/, '$1')