mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 14:23:44 +08:00
chore: check the validity of the rule content
This commit is contained in:
parent
7e8b65e61f
commit
83947b6725
@ -217,6 +217,31 @@ export const RulesEditorViewer = (props: Props) => {
|
|||||||
fetchProfile();
|
fetchProfile();
|
||||||
}, [open]);
|
}, [open]);
|
||||||
|
|
||||||
|
const spliceRule = () => {
|
||||||
|
if (ruleContent === "") return "";
|
||||||
|
// Check valid by regex
|
||||||
|
switch (ruleType) {
|
||||||
|
case "IP-CIDR": {
|
||||||
|
let v4regex = new RegExp(
|
||||||
|
"^((?:(?:[1-9]?[0-9]|1[0-9][0-9]|2(?:[0-4][0-9]|5[0-5]))\\.){3}(?:[1-9]?[0-9]|1[0-9][0-9]|2(?:[0-4][0-9]|5[0-5])))?:(?:[0-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-5]{2}[0-3][0-5])$"
|
||||||
|
);
|
||||||
|
let v6regex = new RegExp(
|
||||||
|
"^([0-9a-fA-F]{1,4}(?::[0-9a-fA-F]{1,4}){7}|::|:(?::[0-9a-fA-F]{1,4}){1,6}|[0-9a-fA-F]{1,4}:(?::[0-9a-fA-F]{1,4}){1,5}|(?:[0-9a-fA-F]{1,4}:){2}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){3}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){4}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){5}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,6}:)\\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$"
|
||||||
|
);
|
||||||
|
if (!v4regex.test(ruleContent) && !v6regex.test(ruleContent)) return "";
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return `${ruleType}${
|
||||||
|
ruleType === "MATCH" ? "" : "," + ruleContent
|
||||||
|
},${proxyPolicy}${
|
||||||
|
NoResolveList.includes(ruleType) && noResolve ? ",no-resolve" : ""
|
||||||
|
}`;
|
||||||
|
};
|
||||||
|
|
||||||
const onSave = useLockFn(async () => {
|
const onSave = useLockFn(async () => {
|
||||||
try {
|
try {
|
||||||
let currData = yaml.dump({
|
let currData = yaml.dump({
|
||||||
@ -325,13 +350,11 @@ export const RulesEditorViewer = (props: Props) => {
|
|||||||
fullWidth
|
fullWidth
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
let raw = `${ruleType}${
|
let raw = spliceRule();
|
||||||
ruleType === "MATCH" ? "" : "," + ruleContent
|
if (raw === "") {
|
||||||
},${proxyPolicy}${
|
Notice.error(t("Invalid Rule"));
|
||||||
NoResolveList.includes(ruleType) && noResolve
|
return;
|
||||||
? ",no-resolve"
|
}
|
||||||
: ""
|
|
||||||
}`;
|
|
||||||
if (prependSeq.includes(raw)) return;
|
if (prependSeq.includes(raw)) return;
|
||||||
setPrependSeq([...prependSeq, raw]);
|
setPrependSeq([...prependSeq, raw]);
|
||||||
}}
|
}}
|
||||||
@ -344,13 +367,11 @@ export const RulesEditorViewer = (props: Props) => {
|
|||||||
fullWidth
|
fullWidth
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
let raw = `${ruleType}${
|
let raw = spliceRule();
|
||||||
ruleType === "MATCH" ? "" : "," + ruleContent
|
if (raw === "") {
|
||||||
},${proxyPolicy}${
|
Notice.error(t("Invalid Rule"));
|
||||||
NoResolveList.includes(ruleType) && noResolve
|
return;
|
||||||
? ",no-resolve"
|
}
|
||||||
: ""
|
|
||||||
}`;
|
|
||||||
if (appendSeq.includes(raw)) return;
|
if (appendSeq.includes(raw)) return;
|
||||||
setAppendSeq([...appendSeq, raw]);
|
setAppendSeq([...appendSeq, raw]);
|
||||||
}}
|
}}
|
||||||
|
@ -58,6 +58,7 @@
|
|||||||
"No Resolve": "No Resolve",
|
"No Resolve": "No Resolve",
|
||||||
"Add Prepend Rule": "Add Prepend Rule",
|
"Add Prepend Rule": "Add Prepend Rule",
|
||||||
"Add Append Rule": "Add Append Rule",
|
"Add Append Rule": "Add Append Rule",
|
||||||
|
"Invalid Rule": "Invalid Rule",
|
||||||
"Delete Rule": "Delete Rule",
|
"Delete Rule": "Delete Rule",
|
||||||
"Edit Groups": "Edit Proxy Groups",
|
"Edit Groups": "Edit Proxy Groups",
|
||||||
"Extend Config": "Extend Config",
|
"Extend Config": "Extend Config",
|
||||||
|
@ -58,6 +58,7 @@
|
|||||||
"No Resolve": "跳过DNS解析",
|
"No Resolve": "跳过DNS解析",
|
||||||
"Add Prepend Rule": "添加前置规则",
|
"Add Prepend Rule": "添加前置规则",
|
||||||
"Add Append Rule": "添加后置规则",
|
"Add Append Rule": "添加后置规则",
|
||||||
|
"Invalid Rule": "无效规则",
|
||||||
"Delete Rule": "删除规则",
|
"Delete Rule": "删除规则",
|
||||||
"Edit Groups": "编辑代理组",
|
"Edit Groups": "编辑代理组",
|
||||||
"Extend Config": "扩展配置",
|
"Extend Config": "扩展配置",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user