fix: correct vless/trojan validation on some browsers

This commit is contained in:
divocat
2025-10-09 17:31:10 +03:00
parent 52d1c5d95f
commit 9d89258c0c
3 changed files with 46 additions and 42 deletions

View File

@@ -2,7 +2,12 @@ import { ValidationResult } from './types';
export function validateVlessUrl(url: string): ValidationResult {
try {
const parsedUrl = new URL(url);
if (!url.startsWith('vless://')) {
return {
valid: false,
message: _('Invalid VLESS URL: must start with vless://'),
};
}
if (!url || /\s/.test(url)) {
return {
@@ -11,12 +16,8 @@ export function validateVlessUrl(url: string): ValidationResult {
};
}
if (parsedUrl.protocol !== 'vless:') {
return {
valid: false,
message: _('Invalid VLESS URL: must start with vless://'),
};
}
const refinedURL = url.replace('vless://', 'https://');
const parsedUrl = new URL(refinedURL);
if (!parsedUrl.username) {
return { valid: false, message: _('Invalid VLESS URL: missing UUID') };