diff --git a/src/interfaces.cpp b/src/interfaces.cpp index 396365c..2d9ac16 100644 --- a/src/interfaces.cpp +++ b/src/interfaces.cpp @@ -249,6 +249,7 @@ void readGroup(YAML::Node node, string_array &dest) for(i = 0; i < node.size(); i++) { + name.clear(); eraseElements(tempArray); object = node[i]; object["import"] >> name; @@ -292,7 +293,8 @@ void readRuleset(YAML::Node node, string_array &dest) for(unsigned int i = 0; i < node.size(); i++) { - name = ""; + url.clear(); + name.clear(); object = node[i]; object["import"] >> name; if(name.size()) diff --git a/src/misc.cpp b/src/misc.cpp index f1874c8..e8e0a5f 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -618,8 +618,14 @@ bool regValid(const std::string &target) jp::Regex reg(target); return !!reg; } + #endif // USE_STD_REGEX +std::string regTrim(const std::string &src) +{ + return regReplace(src, "^\\s*?(.*?)\\s*$", "$1"); +} + std::string speedCalc(double speed) { if(speed == 0.0) diff --git a/src/misc.h b/src/misc.h index c8838d7..96b7c49 100644 --- a/src/misc.h +++ b/src/misc.h @@ -50,6 +50,7 @@ bool regValid(const std::string &target); bool regFind(const std::string &src, const std::string &match); std::string regReplace(const std::string &src, const std::string &match, const std::string &rep); bool regMatch(const std::string &src, const std::string &match); +std::string regTrim(const std::string &src); std::string speedCalc(double speed); std::string getMD5(const std::string &data); bool isIPv4(const std::string &address); diff --git a/src/subexport.cpp b/src/subexport.cpp index 43b6639..f89ffbc 100644 --- a/src/subexport.cpp +++ b/src/subexport.cpp @@ -403,11 +403,18 @@ void rulesetToClash(YAML::Node &base_rule, std::vector &ruleset while(getline(strStrm, strLine, delimiter)) { lineSize = strLine.size(); + /* if(lineSize && strLine[lineSize - 1] == '\r') //remove line break { strLine.erase(lineSize - 1); lineSize--; } + */ + if(lineSize) + { + strLine = regTrim(strLine); + lineSize = strLine.size(); + } if(!lineSize || strLine[0] == ';' || strLine[0] == '#' || (lineSize >= 2 && strLine[0] == '/' && strLine[1] == '/')) //empty lines and comments are ignored continue; if(strLine.find("USER-AGENT") == 0 || strLine.find("URL-REGEX") == 0 || strLine.find("PROCESS-NAME") == 0 || strLine.find("AND") == 0 || strLine.find("OR") == 0) //remove unsupported types @@ -542,11 +549,18 @@ void rulesetToSurge(INIReader &base_rule, std::vector &ruleset_ while(getline(strStrm, strLine, delimiter)) { lineSize = strLine.size(); + /* if(lineSize && strLine[lineSize - 1] == '\r') //remove line break { strLine.erase(lineSize - 1); lineSize--; } + */ + if(lineSize) + { + strLine = regTrim(strLine); + lineSize = strLine.size(); + } if(!lineSize || strLine[0] == ';' || strLine[0] == '#' || (lineSize >= 2 && strLine[0] == '/' && strLine[1] == '/')) //empty lines and comments are ignored continue; if((surge_ver == -1 || surge_ver == -2) && (strLine.find("IP-CIDR6") == 0 || strLine.find("URL-REGEX") == 0 || strLine.find("PROCESS-NAME") == 0 || strLine.find("AND") == 0 || strLine.find("OR") == 0)) //remove unsupported types