Fix: use punycode.toASCII in trie dumping

This commit is contained in:
SukkaW
2025-03-17 17:31:22 +08:00
parent 62b93bbc03
commit 78f5b83b39
6 changed files with 24 additions and 10 deletions

View File

@@ -42,7 +42,7 @@ export const downloadPreviousBuild = task(require.main === module, __filename)(a
{ {
method: 'GET', method: 'GET',
headers: { headers: {
'User-Agent': 'curl/8.9.1', 'User-Agent': 'curl/8.12.1',
// https://github.com/unjs/giget/issues/97 // https://github.com/unjs/giget/issues/97
// https://gitlab.com/gitlab-org/gitlab/-/commit/50c11f278d18fe1f3fb12eb595067216bb58ade2 // https://gitlab.com/gitlab-org/gitlab/-/commit/50c11f278d18fe1f3fb12eb595067216bb58ade2
'sec-fetch-mode': 'same-origin' 'sec-fetch-mode': 'same-origin'

View File

@@ -152,7 +152,7 @@ export class ResponseError<T extends UndiciResponseData | Response> extends Erro
export const defaultRequestInit = { export const defaultRequestInit = {
headers: { headers: {
'User-Agent': 'curl/8.9.1 (https://github.com/SukkaW/Surge)' 'User-Agent': 'curl/8.12.1 (https://github.com/SukkaW/Surge)'
} }
}; };

View File

@@ -8,6 +8,7 @@ import { noop } from 'foxts/noop';
import { fastStringArrayJoin } from 'foxts/fast-string-array-join'; import { fastStringArrayJoin } from 'foxts/fast-string-array-join';
import { deleteBit, getBit, missingBit, setBit } from 'foxts/bitwise'; import { deleteBit, getBit, missingBit, setBit } from 'foxts/bitwise';
import { toASCII } from 'punycode/';
const START = 1 << 1; const START = 1 << 1;
const INCLUDE_ALL_SUBDOMAIN = 1 << 2; const INCLUDE_ALL_SUBDOMAIN = 1 << 2;
@@ -358,13 +359,13 @@ abstract class Triebase<Meta = unknown> {
const onMatches = subdomainOnly const onMatches = subdomainOnly
? (suffix: string[], subdomain: boolean) => { // fast path (default option) ? (suffix: string[], subdomain: boolean) => { // fast path (default option)
const d = fastStringArrayJoin(suffix, '.'); const d = toASCII(fastStringArrayJoin(suffix, '.'));
if (!subdomain && subStringEqual(inputSuffix, d, 1)) return; if (!subdomain && subStringEqual(inputSuffix, d, 1)) return;
results.push(subdomain ? '.' + d : d); results.push(subdomain ? '.' + d : d);
} }
: (suffix: string[], subdomain: boolean) => { // fast path (default option) : (suffix: string[], subdomain: boolean) => { // fast path (default option)
const d = fastStringArrayJoin(suffix, '.'); const d = toASCII(fastStringArrayJoin(suffix, '.'));
results.push(subdomain ? '.' + d : d); results.push(subdomain ? '.' + d : d);
}; };
@@ -417,7 +418,7 @@ abstract class Triebase<Meta = unknown> {
public dumpWithoutDot(onSuffix: (suffix: string, subdomain: boolean) => void, withSort = false) { public dumpWithoutDot(onSuffix: (suffix: string, subdomain: boolean) => void, withSort = false) {
const handleSuffix = (suffix: string[], subdomain: boolean) => { const handleSuffix = (suffix: string[], subdomain: boolean) => {
onSuffix(fastStringArrayJoin(suffix, '.'), subdomain); onSuffix(toASCII(fastStringArrayJoin(suffix, '.')), subdomain);
}; };
if (withSort) { if (withSort) {
@@ -434,11 +435,11 @@ abstract class Triebase<Meta = unknown> {
const handleSuffix = onSuffix const handleSuffix = onSuffix
? (suffix: string[], subdomain: boolean) => { ? (suffix: string[], subdomain: boolean) => {
const d = fastStringArrayJoin(suffix, '.'); const d = toASCII(fastStringArrayJoin(suffix, '.'));
onSuffix(subdomain ? '.' + d : d); onSuffix(subdomain ? '.' + d : d);
} }
: (suffix: string[], subdomain: boolean) => { : (suffix: string[], subdomain: boolean) => {
const d = fastStringArrayJoin(suffix, '.'); const d = toASCII(fastStringArrayJoin(suffix, '.'));
results.push(subdomain ? '.' + d : d); results.push(subdomain ? '.' + d : d);
}; };
@@ -476,11 +477,11 @@ abstract class Triebase<Meta = unknown> {
const handleSuffix = onSuffix const handleSuffix = onSuffix
? (suffix: string[], subdomain: boolean, meta: Meta | undefined) => { ? (suffix: string[], subdomain: boolean, meta: Meta | undefined) => {
const d = fastStringArrayJoin(suffix, '.'); const d = toASCII(fastStringArrayJoin(suffix, '.'));
return onSuffix(subdomain ? '.' + d : d, meta); return onSuffix(subdomain ? '.' + d : d, meta);
} }
: (suffix: string[], subdomain: boolean, meta: Meta | undefined) => { : (suffix: string[], subdomain: boolean, meta: Meta | undefined) => {
const d = fastStringArrayJoin(suffix, '.'); const d = toASCII(fastStringArrayJoin(suffix, '.'));
results.push([subdomain ? '.' + d : d, meta]); results.push([subdomain ? '.' + d : d, meta]);
}; };

View File

@@ -70,7 +70,7 @@ export async function parseGfwList() {
const res = await (await $$fetch('https://litter.catbox.moe/gv0bw6.csv', { const res = await (await $$fetch('https://litter.catbox.moe/gv0bw6.csv', {
headers: { headers: {
accept: '*/*', accept: '*/*',
'user-agent': 'curl/8.9.1' 'user-agent': 'curl/8.12.1'
} }
})).text(); })).text();
const topDomains = parse(res); const topDomains = parse(res);

View File

@@ -35,6 +35,7 @@
"hash-wasm": "^4.12.0", "hash-wasm": "^4.12.0",
"json-stringify-pretty-compact": "3.0.0", "json-stringify-pretty-compact": "3.0.0",
"picocolors": "^1.1.1", "picocolors": "^1.1.1",
"punycode": "^2.3.1",
"tar-fs": "^3.0.8", "tar-fs": "^3.0.8",
"tinyexec": "^0.3.2", "tinyexec": "^0.3.2",
"tldts": "^6.1.84", "tldts": "^6.1.84",
@@ -57,6 +58,7 @@
"@types/fast-fifo": "^1.3.0", "@types/fast-fifo": "^1.3.0",
"@types/mocha": "^10.0.10", "@types/mocha": "^10.0.10",
"@types/node": "^22.13.10", "@types/node": "^22.13.10",
"@types/punycode": "^2.1.4",
"@types/tar-fs": "^2.0.4", "@types/tar-fs": "^2.0.4",
"eslint": "^9.22.0", "eslint": "^9.22.0",
"eslint-config-sukka": "^6.17.0", "eslint-config-sukka": "^6.17.0",

11
pnpm-lock.yaml generated
View File

@@ -61,6 +61,9 @@ importers:
picocolors: picocolors:
specifier: ^1.1.1 specifier: ^1.1.1
version: 1.1.1 version: 1.1.1
punycode:
specifier: ^2.3.1
version: 2.3.1
tar-fs: tar-fs:
specifier: ^3.0.8 specifier: ^3.0.8
version: 3.0.8 version: 3.0.8
@@ -122,6 +125,9 @@ importers:
'@types/node': '@types/node':
specifier: ^22.13.10 specifier: ^22.13.10
version: 22.13.10 version: 22.13.10
'@types/punycode':
specifier: ^2.1.4
version: 2.1.4
'@types/tar-fs': '@types/tar-fs':
specifier: ^2.0.4 specifier: ^2.0.4
version: 2.0.4 version: 2.0.4
@@ -553,6 +559,9 @@ packages:
'@types/node@22.13.10': '@types/node@22.13.10':
resolution: {integrity: sha512-I6LPUvlRH+O6VRUqYOcMudhaIdUVWfsjnZavnsraHvpBwaEyMN29ry+0UVJhImYL16xsscu0aske3yA+uPOWfw==} resolution: {integrity: sha512-I6LPUvlRH+O6VRUqYOcMudhaIdUVWfsjnZavnsraHvpBwaEyMN29ry+0UVJhImYL16xsscu0aske3yA+uPOWfw==}
'@types/punycode@2.1.4':
resolution: {integrity: sha512-trzh6NzBnq8yw5e35f8xe8VTYjqM3NE7bohBtvDVf/dtUer3zYTLK1Ka3DG3p7bdtoaOHZucma6FfVKlQ134pQ==}
'@types/retry@0.12.5': '@types/retry@0.12.5':
resolution: {integrity: sha512-3xSjTp3v03X/lSQLkczaN9UIEwJMoMCA1+Nb5HfbJEQWogdeQIyVtTvxPXDQjZ5zws8rFQfVfRdz03ARihPJgw==} resolution: {integrity: sha512-3xSjTp3v03X/lSQLkczaN9UIEwJMoMCA1+Nb5HfbJEQWogdeQIyVtTvxPXDQjZ5zws8rFQfVfRdz03ARihPJgw==}
@@ -2142,6 +2151,8 @@ snapshots:
dependencies: dependencies:
undici-types: 6.20.0 undici-types: 6.20.0
'@types/punycode@2.1.4': {}
'@types/retry@0.12.5': {} '@types/retry@0.12.5': {}
'@types/stack-utils@2.0.3': {} '@types/stack-utils@2.0.3': {}