From 05959b09b4c589faf1c155685805e8d03ea5ed6c Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Thu, 16 Jan 2025 17:11:45 +0800 Subject: [PATCH] Url-decode file name before adding as Clash rule provider (#815) --- src/generator/template/templates.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/generator/template/templates.cpp b/src/generator/template/templates.cpp index 75ed31ac9..0f53adcde 100644 --- a/src/generator/template/templates.cpp +++ b/src/generator/template/templates.cpp @@ -386,10 +386,10 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rulese if(fileExist(rule_path, true) || isLink(rule_path)) { //rule_name = std::to_string(hash_(rule_group + rule_path)); - rule_name = old_rule_name = findFileName(rule_path); + rule_name = old_rule_name = urlDecode(findFileName(rule_path)); int idx = 2; while(std::find(groups.begin(), groups.end(), rule_name) != groups.end()) - rule_name = old_rule_name + "_" + std::to_string(idx++); + rule_name = old_rule_name + " " + std::to_string(idx++); names[rule_name] = rule_group; urls[rule_name] = rule_path_typed; rule_type[rule_name] = x.rule_type; @@ -436,9 +436,9 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rulese if(vArray.size() < 2) continue; if(keywords.find(rule_name) == keywords.end()) - keywords[rule_name] = "\"" + vArray[1] + "\""; + keywords[rule_name] = "\"" + trim(vArray[1]) + "\""; else - keywords[rule_name] += ",\"" + vArray[1] + "\""; + keywords[rule_name] += ",\"" + trim(vArray[1]) + "\""; } else { @@ -449,7 +449,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rulese } else { - strLine = vArray[0] + "," + vArray[1] + "," + rule_group; + strLine = vArray[0] + "," + trim(vArray[1]) + "," + rule_group; if(vArray.size() > 2) strLine += "," + vArray[2]; } @@ -466,13 +466,13 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rulese } } if(has_domain[rule_name] && !script) - rules.emplace_back("RULE-SET," + rule_name + "_domain," + rule_group); + rules.emplace_back("RULE-SET," + rule_name + " (Domain)," + rule_group); if(has_ipcidr[rule_name] && !script) { if(has_no_resolve) - rules.emplace_back("RULE-SET," + rule_name + "_ipcidr," + rule_group + ",no-resolve"); + rules.emplace_back("RULE-SET," + rule_name + " (IP-CIDR)," + rule_group + ",no-resolve"); else - rules.emplace_back("RULE-SET," + rule_name + "_ipcidr," + rule_group); + rules.emplace_back("RULE-SET," + rule_name + " (IP-CIDR)," + rule_group); } if(!has_domain[rule_name] && !has_ipcidr[rule_name] && !script) rules.emplace_back("RULE-SET," + rule_name + "," + rule_group); @@ -490,14 +490,14 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rulese { std::string yaml_key = x; if(rule_type[x] != RULESET_CLASH_DOMAIN) - yaml_key += "_domain"; + yaml_key += " (Domain)"; base_rule["rule-providers"][yaml_key]["type"] = "http"; base_rule["rule-providers"][yaml_key]["behavior"] = "domain"; if(url[0] == '*') base_rule["rule-providers"][yaml_key]["url"] = url.substr(1); else base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=3&url=" + urlSafeBase64Encode(url); - base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml"; + base_rule["rule-providers"][yaml_key]["path"] = "./providers/" + std::to_string(hash_(url)) + "_domain.yaml"; if(interval) base_rule["rule-providers"][yaml_key]["interval"] = interval; } @@ -505,14 +505,14 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rulese { std::string yaml_key = x; if(rule_type[x] != RULESET_CLASH_IPCIDR) - yaml_key += "_ipcidr"; + yaml_key += " (IP-CIDR)"; base_rule["rule-providers"][yaml_key]["type"] = "http"; base_rule["rule-providers"][yaml_key]["behavior"] = "ipcidr"; if(url[0] == '*') base_rule["rule-providers"][yaml_key]["url"] = url.substr(1); else base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=4&url=" + urlSafeBase64Encode(url); - base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml"; + base_rule["rule-providers"][yaml_key]["path"] = "./providers/" + std::to_string(hash_(url)) + "_ipcidr.yaml"; if(interval) base_rule["rule-providers"][yaml_key]["interval"] = interval; } @@ -525,7 +525,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rulese base_rule["rule-providers"][yaml_key]["url"] = url.substr(1); else base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=6&url=" + urlSafeBase64Encode(url); - base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml"; + base_rule["rule-providers"][yaml_key]["path"] = "./providers/" + std::to_string(hash_(url)) + ".yaml"; if(interval) base_rule["rule-providers"][yaml_key]["interval"] = interval; }