Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(generator/ruleconvert): clash rule-provider without payload: #752

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions src/generator/config/ruleconvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
{
Expand All @@ -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';
Expand Down