Allow special characters in rule-set tags
Some checks failed
Build and Deploy Gateway / build-and-deploy (push) Failing after 13s
Some checks failed
Build and Deploy Gateway / build-and-deploy (push) Failing after 13s
This commit is contained in:
@@ -21,9 +21,12 @@ import { matchRoute, detectRuleConflicts } from "./routeMatcher.js";
|
||||
import { tcpPing, resolveHost } from "./ping.js";
|
||||
|
||||
const APPLY_HISTORY_LIMIT = 10;
|
||||
const RULE_SET_TAG_RE = /^[a-z0-9][a-z0-9_.@!-]*$/i;
|
||||
const FALLBACK_RULE_SET_CATALOG = {
|
||||
geosite: [
|
||||
"geosite-category-ru",
|
||||
"geosite-category-ai-!cn",
|
||||
"geosite-geolocation-!cn",
|
||||
"geosite-google",
|
||||
"geosite-youtube",
|
||||
"geosite-telegram",
|
||||
@@ -648,7 +651,7 @@ function normalizeCustomRules(input) {
|
||||
["tcp", "udp"].includes(network),
|
||||
),
|
||||
ruleSets: normalizeList(rule.ruleSets).filter((tag) =>
|
||||
/^[a-z0-9][a-z0-9-]*$/i.test(tag),
|
||||
RULE_SET_TAG_RE.test(tag),
|
||||
),
|
||||
}));
|
||||
}
|
||||
@@ -938,7 +941,7 @@ async function handleApi(req, res) {
|
||||
url: String(rs.url).trim(),
|
||||
format: rs.format === "source" ? "source" : "binary",
|
||||
}))
|
||||
.filter((rs) => /^[a-z0-9][a-z0-9-]*$/i.test(rs.tag));
|
||||
.filter((rs) => RULE_SET_TAG_RE.test(rs.tag));
|
||||
writeJson(settings.customRuleSetsPath, normalized);
|
||||
return sendJson(res, 200, { success: true, ruleSets: normalized });
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { isValidCidr, isValidPort, ruleErrors, hasErrors } from '../utils/valida
|
||||
import { api } from '../api.js';
|
||||
|
||||
const DOMAIN = /^(?=.{1,253}$)([a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)(\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i;
|
||||
const RULE_SET_TAG = /^[a-z0-9][a-z0-9-]*$/i;
|
||||
const RULE_SET_TAG = /^[a-z0-9][a-z0-9_.@!-]*$/i;
|
||||
const validDomain = (v) => DOMAIN.test(String(v).trim());
|
||||
const validRuleSetTag = (v) => RULE_SET_TAG.test(String(v).trim());
|
||||
|
||||
|
||||
@@ -601,8 +601,8 @@ function RuleSetsCard({ pushToast }) {
|
||||
const tag = newTag.trim();
|
||||
const url = newUrl.trim();
|
||||
if (!tag || !url) return;
|
||||
if (!/^[a-z0-9][a-z0-9-]*$/i.test(tag)) {
|
||||
pushToast({ kind: 'danger', title: 'Невалидный тег', message: 'Только буквы, цифры, дефис' });
|
||||
if (!/^[a-z0-9][a-z0-9_.@!-]*$/i.test(tag)) {
|
||||
pushToast({ kind: 'danger', title: 'Невалидный тег', message: 'Буквы, цифры и символы - _ . @ !' });
|
||||
return;
|
||||
}
|
||||
if (ruleSets.some((rs) => rs.tag === tag)) {
|
||||
|
||||
Reference in New Issue
Block a user