mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-06 03:26:51 +03:00
fix: allow .tld for user_domains_text & user_domains
This commit is contained in:
@@ -29,6 +29,13 @@ export const invalidDomains = [
|
||||
['Too long domain (>253 chars)', Array(40).fill('abcdef').join('.') + '.com'],
|
||||
];
|
||||
|
||||
export const dotTLDTests = [
|
||||
['Dot TLD allowed (.net)', '.net', true, true],
|
||||
['Dot TLD not allowed (.net)', '.net', false, false],
|
||||
['Invalid with double dot', '..net', true, false],
|
||||
['Invalid single word TLD (net)', 'net', true, false],
|
||||
];
|
||||
|
||||
describe('validateDomain', () => {
|
||||
describe.each(validDomains)('Valid domain: %s', (_desc, domain) => {
|
||||
it(`returns valid=true for "${domain}"`, () => {
|
||||
@@ -43,4 +50,14 @@ describe('validateDomain', () => {
|
||||
expect(res.valid).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe.each(dotTLDTests)(
|
||||
'Dot TLD toggle: %s',
|
||||
(_desc, domain, allowDotTLD, expected) => {
|
||||
it(`"${domain}" with allowDotTLD=${allowDotTLD} → valid=${expected}`, () => {
|
||||
const res = validateDomain(domain, allowDotTLD);
|
||||
expect(res.valid).toBe(expected);
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
import { ValidationResult } from './types';
|
||||
|
||||
export function validateDomain(domain: string): ValidationResult {
|
||||
export function validateDomain(
|
||||
domain: string,
|
||||
allowDotTLD = false
|
||||
): ValidationResult {
|
||||
const domainRegex =
|
||||
/^(?=.{1,253}(?:\/|$))(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)\.)+(?:[a-zA-Z]{2,}|xn--[a-zA-Z0-9-]{1,59}[a-zA-Z0-9])(?:\/[^\s]*)?$/;
|
||||
/^(?=.{1,253}(?:\/|$))(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)\.)+(?:[a-zA-Z]{2,}|xn--[a-zA-Z0-9-]{1,59}[a-zA-Z0-9])(?:\/[^\s]*)?$/;
|
||||
|
||||
if (allowDotTLD) {
|
||||
const dotTLD = /^\.[a-zA-Z]{2,}$/;
|
||||
if (dotTLD.test(domain)) {
|
||||
return { valid: true, message: _('Valid') };
|
||||
}
|
||||
}
|
||||
|
||||
if (!domainRegex.test(domain)) {
|
||||
return { valid: false, message: _('Invalid domain address') };
|
||||
|
||||
@@ -455,7 +455,7 @@ function createConfigSection(section) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const validation = main.validateDomain(value);
|
||||
const validation = main.validateDomain(value, true);
|
||||
|
||||
if (validation.valid) {
|
||||
return true;
|
||||
@@ -493,7 +493,7 @@ function createConfigSection(section) {
|
||||
);
|
||||
}
|
||||
|
||||
const { valid, results } = main.bulkValidate(domains, main.validateDomain);
|
||||
const { valid, results } = main.bulkValidate(domains, row => main.validateDomain(row, true));
|
||||
|
||||
if (!valid) {
|
||||
const errors = results
|
||||
|
||||
@@ -14,8 +14,14 @@ function validateIPV4(ip) {
|
||||
}
|
||||
|
||||
// src/validators/validateDomain.ts
|
||||
function validateDomain(domain) {
|
||||
function validateDomain(domain, allowDotTLD = false) {
|
||||
const domainRegex = /^(?=.{1,253}(?:\/|$))(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)\.)+(?:[a-zA-Z]{2,}|xn--[a-zA-Z0-9-]{1,59}[a-zA-Z0-9])(?:\/[^\s]*)?$/;
|
||||
if (allowDotTLD) {
|
||||
const dotTLD = /^\.[a-zA-Z]{2,}$/;
|
||||
if (dotTLD.test(domain)) {
|
||||
return { valid: true, message: _("Valid") };
|
||||
}
|
||||
}
|
||||
if (!domainRegex.test(domain)) {
|
||||
return { valid: false, message: _("Invalid domain address") };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user