fix: implement query params parsing func

This commit is contained in:
divocat
2025-10-10 14:06:19 +03:00
parent 715a278af8
commit 0493565c5f
4 changed files with 209 additions and 183 deletions

View File

@@ -9,3 +9,4 @@ export * from './onMount';
export * from './getClashApiUrl';
export * from './splitProxyString';
export * from './preserveScrollForPage';
export * from './parseQueryString';

View File

@@ -0,0 +1,22 @@
export function parseQueryString(query: string): Record<string, string> {
const clean = query.startsWith('?') ? query.slice(1) : query;
return clean
.split('&')
.filter(Boolean)
.reduce(
(acc, pair) => {
const [rawKey, rawValue = ''] = pair.split('=');
if (!rawKey) {
return acc;
}
const key = decodeURIComponent(rawKey);
const value = decodeURIComponent(rawValue);
return { ...acc, [key]: value };
},
{} as Record<string, string>,
);
}

View File

@@ -1,4 +1,5 @@
import { ValidationResult } from './types';
import { parseQueryString } from '../helpers';
export function validateVlessUrl(url: string): ValidationResult {
try {
@@ -55,17 +56,7 @@ export function validateVlessUrl(url: string): ValidationResult {
message: 'Invalid VLESS URL: missing query parameters',
};
const params = queryString
.split('&')
.filter(Boolean)
.map((pair) => pair.split('='))
.reduce(
(acc, [key, value = '']) => {
if (key) acc[key] = value;
return acc;
},
{} as Record<string, string>,
);
const params = parseQueryString(queryString);
const validTypes = [
'tcp',