From 1ef68b1c145a6c7522f2cf25c22099a9bc5d007f Mon Sep 17 00:00:00 2001 From: ChrAlpha <53332481+ChrAlpha@users.noreply.github.com> Date: Sat, 4 May 2024 23:57:31 +0800 Subject: [PATCH 1/2] fix(generator/ruleconvert): clash-domain:/clash-ipcidr: on online ruleset that without `payload:` --- src/generator/config/ruleconvert.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generator/config/ruleconvert.cpp b/src/generator/config/ruleconvert.cpp index f98e34654..9a045d57e 100644 --- a/src/generator/config/ruleconvert.cpp +++ b/src/generator/config/ruleconvert.cpp @@ -28,7 +28,7 @@ std::string convertRuleset(const std::string &content, int type) if(type == RULESET_SURGE) return content; - if(regFind(content, "^payload:\\r?\\n")) /// Clash + if(regFind(content, "^payload:\\r?\\n") || (type == RULESET_CLASH_DOMAIN || type == RULESET_CLASH_IPCIDR)) /// Clash { output = regReplace(regReplace(content, "payload:\\r?\\n", "", true), R"(\s?^\s*-\s+('|"?)(.*)\1$)", "\n$2", true); if(type == RULESET_CLASH_CLASSICAL) /// classical type From 8ae4885fae7e8855005c2895d10a05b4c4e2b978 Mon Sep 17 00:00:00 2001 From: ChrAlpha <53332481+ChrAlpha@users.noreply.github.com> Date: Sun, 5 May 2024 13:47:49 +0800 Subject: [PATCH 2/2] fix(generator/ruleconvert): clash-domain:/clash-ipcidr: on online ruleset that without `payload:` --- src/generator/config/ruleconvert.cpp | 50 +++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/src/generator/config/ruleconvert.cpp b/src/generator/config/ruleconvert.cpp index 9a045d57e..30a34472c 100644 --- a/src/generator/config/ruleconvert.cpp +++ b/src/generator/config/ruleconvert.cpp @@ -53,15 +53,18 @@ std::string convertRuleset(const std::string &content, int type) if(!strLine.empty() && (strLine[0] != ';' && strLine[0] != '#' && !(lineSize >= 2 && strLine[0] == '/' && strLine[1] == '/'))) { - pos = strLine.find('/'); - if(pos != std::string::npos) /// ipcidr + if(type == RULESET_CLASH_IPCIDR) { - if(isIPv4(strLine.substr(0, pos))) - output += "IP-CIDR,"; - else - output += "IP-CIDR6,"; - } - else + pos = strLine.find('/'); + if(pos != std::string::npos) /// ipcidr + { + if(isIPv4(strLine.substr(0, pos))) + output += "IP-CIDR,"; + else + output += "IP-CIDR6,"; + } + } + else if (type == RULESET_CLASH_DOMAIN) { if(strLine[0] == '.' || (lineSize >= 2 && strLine[0] == '+' && strLine[1] == '.')) /// suffix { @@ -81,6 +84,37 @@ std::string convertRuleset(const std::string &content, int type) else output += "DOMAIN,"; } + else + { + pos = strLine.find('/'); + if(pos != std::string::npos) /// ipcidr + { + if(isIPv4(strLine.substr(0, pos))) + output += "IP-CIDR,"; + else + output += "IP-CIDR6,"; + } + else + { + if(strLine[0] == '.' || (lineSize >= 2 && strLine[0] == '+' && strLine[1] == '.')) /// suffix + { + bool keyword_flag = false; + while(endsWith(strLine, ".*")) + { + keyword_flag = true; + strLine.erase(strLine.size() - 2); + } + output += "DOMAIN-"; + if(keyword_flag) + output += "KEYWORD,"; + else + output += "SUFFIX,"; + strLine.erase(0, 2 - (strLine[0] == '.')); + } + else + output += "DOMAIN,"; + } + } } output += strLine; output += '\n';