From 6164dda6bccafb133507ced5ab274ca6a1fb5577 Mon Sep 17 00:00:00 2001 From: Optimus Primal <32876945+mwhds97@users.noreply.github.com> Date: Sat, 12 Dec 2020 14:33:48 +0800 Subject: [PATCH 1/5] Fix sort_script problem --- src/interfaces.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/interfaces.cpp b/src/interfaces.cpp index 3112823bc..cd7e6af48 100644 --- a/src/interfaces.cpp +++ b/src/interfaces.cpp @@ -1362,12 +1362,12 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS) std::string argIncludeRemark = UrlDecode(getUrlArg(argument, "include")), argExcludeRemark = UrlDecode(getUrlArg(argument, "exclude")); std::string argCustomGroups = urlsafe_base64_decode(getUrlArg(argument, "groups")), argCustomRulesets = urlsafe_base64_decode(getUrlArg(argument, "ruleset")), argExternalConfig = UrlDecode(getUrlArg(argument, "config")); std::string argDeviceID = getUrlArg(argument, "dev_id"), argFilename = getUrlArg(argument, "filename"), argUpdateInterval = getUrlArg(argument, "interval"), argUpdateStrict = getUrlArg(argument, "strict"); - std::string argRenames = UrlDecode(getUrlArg(argument, "rename")), argFilterScript = UrlDecode(getUrlArg(argument, "filter_script")); + std::string argRenames = UrlDecode(getUrlArg(argument, "rename")), argFilterScript = UrlDecode(getUrlArg(argument, "filter_script")), argSortScript = UrlDecode(getUrlArg(argument, "sort_script")); /// switches with default value tribool argUpload = getUrlArg(argument, "upload"), argEmoji = getUrlArg(argument, "emoji"), argAddEmoji = getUrlArg(argument, "add_emoji"), argRemoveEmoji = getUrlArg(argument, "remove_emoji"); tribool argAppendType = getUrlArg(argument, "append_type"), argTFO = getUrlArg(argument, "tfo"), argUDP = getUrlArg(argument, "udp"), argGenNodeList = getUrlArg(argument, "list"); - tribool argSort = getUrlArg(argument, "sort"), argUseSortScript = getUrlArg(argument, "sort_script"); + tribool argSort = getUrlArg(argument, "sort"); tribool argGenClashScript = getUrlArg(argument, "script"), argEnableInsert = getUrlArg(argument, "insert"); tribool argSkipCertVerify = getUrlArg(argument, "scv"), argFilterDeprecated = getUrlArg(argument, "fdn"), argExpandRulesets = getUrlArg(argument, "expand"), argAppendUserinfo = getUrlArg(argument, "append_info"); tribool argPrependInsert = getUrlArg(argument, "prepend"), argGenClassicalRuleProvider = getUrlArg(argument, "classic"), argTLS13 = getUrlArg(argument, "tls13"); @@ -1435,8 +1435,9 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS) ext.tls13.parse(argTLS13).parse(gTLS13); ext.sort_flag = argSort.get(gEnableSort); - argUseSortScript.define(gSortScript.size() != 0); - if(ext.sort_flag && argUseSortScript) + if(authorized && !argSortScript.empty()) + gSortScript = argSortScript; + if(ext.sort_flag) ext.sort_script = gSortScript; ext.filter_deprecated = argFilterDeprecated.get(gFilterDeprecated); ext.clash_new_field_name = argClashNewField.get(gClashUseNewField); From 24a25c6a39ffa0c74f4d3c8f53a744208d446035 Mon Sep 17 00:00:00 2001 From: Optimus Primal <32876945+mwhds97@users.noreply.github.com> Date: Sun, 13 Dec 2020 00:56:34 +0800 Subject: [PATCH 2/5] Use stable sort algorithm to sort nodes --- src/subexport.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/subexport.cpp b/src/subexport.cpp index bee5d6a8f..bfef9b9aa 100644 --- a/src/subexport.cpp +++ b/src/subexport.cpp @@ -1099,7 +1099,7 @@ void preprocessNodes(std::vector &nodes, const extra_settings &ext) duk_pcall(ctx, 2); return duktape_get_res_int(ctx); }; - std::sort(nodes.begin(), nodes.end(), comparer); + std::stable_sort(nodes.begin(), nodes.end(), comparer); failed = false; } else @@ -1114,7 +1114,7 @@ void preprocessNodes(std::vector &nodes, const extra_settings &ext) //failed } } - if(failed) std::sort(nodes.begin(), nodes.end(), [](const nodeInfo &a, const nodeInfo &b) + if(failed) std::stable_sort(nodes.begin(), nodes.end(), [](const nodeInfo &a, const nodeInfo &b) { return a.remarks < b.remarks; }); From 91186d3abb2b341a5a6c608e8f59bb2d8204cfbc Mon Sep 17 00:00:00 2001 From: Optimus Primal <32876945+mwhds97@users.noreply.github.com> Date: Fri, 18 Dec 2020 05:20:47 +0800 Subject: [PATCH 3/5] Fix local script file --- src/interfaces.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/interfaces.cpp b/src/interfaces.cpp index cd7e6af48..809899f78 100644 --- a/src/interfaces.cpp +++ b/src/interfaces.cpp @@ -693,8 +693,6 @@ void readYAMLConf(YAML::Node &node) if(section["include_remarks"].IsSequence()) section["include_remarks"] >> gIncludeRemarks; gFilterScript = safe_as(section["enable_filter"]) ? safe_as(section["filter_script"]) : ""; - if(startsWith(gFilterScript, "path:")) - gFilterScript = fileGet(gFilterScript.substr(5), false); section["base_path"] >> gBasePath; section["clash_rule_base"] >> gClashBase; section["surge_rule_base"] >> gSurgeBase; @@ -1437,6 +1435,8 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS) ext.sort_flag = argSort.get(gEnableSort); if(authorized && !argSortScript.empty()) gSortScript = argSortScript; + if(startsWith(gSortScript, "path:")) + gSortScript = fileGet(gSortScript.substr(5), false); if(ext.sort_flag) ext.sort_script = gSortScript; ext.filter_deprecated = argFilterDeprecated.get(gFilterDeprecated); @@ -1615,6 +1615,8 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS) std::string filterScript = gFilterScript; if(authorized && !argFilterScript.empty()) filterScript = argFilterScript; + if(startsWith(filterScript, "path:")) + filterScript = fileGet(filterScript.substr(5), false); if(filterScript.size()) { if(startsWith(filterScript, "path:")) From 37396c2d2645754fad3b20799e6f4a8da5001f51 Mon Sep 17 00:00:00 2001 From: Optimus Primal <32876945+mwhds97@users.noreply.github.com> Date: Fri, 18 Dec 2020 13:22:36 +0800 Subject: [PATCH 4/5] Update interfaces.cpp --- src/interfaces.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/interfaces.cpp b/src/interfaces.cpp index 809899f78..92fca50cc 100644 --- a/src/interfaces.cpp +++ b/src/interfaces.cpp @@ -1433,12 +1433,13 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS) ext.tls13.parse(argTLS13).parse(gTLS13); ext.sort_flag = argSort.get(gEnableSort); + std::string sortScript = gSortScript; if(authorized && !argSortScript.empty()) - gSortScript = argSortScript; - if(startsWith(gSortScript, "path:")) - gSortScript = fileGet(gSortScript.substr(5), false); + sortScript = argSortScript; + if(startsWith(sortScript, "path:")) + sortScript = fileGet(sortScript.substr(5), false); if(ext.sort_flag) - ext.sort_script = gSortScript; + ext.sort_script = sortScript; ext.filter_deprecated = argFilterDeprecated.get(gFilterDeprecated); ext.clash_new_field_name = argClashNewField.get(gClashUseNewField); ext.clash_script = argGenClashScript.get(); From 549eaa56fadd17ae8bfbac702cb1cccbee0c4f85 Mon Sep 17 00:00:00 2001 From: Optimus Primal <32876945+mwhds97@users.noreply.github.com> Date: Wed, 23 Dec 2020 17:38:41 +0800 Subject: [PATCH 5/5] Update interfaces.cpp --- src/interfaces.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/interfaces.cpp b/src/interfaces.cpp index 92fca50cc..96f56a6b8 100644 --- a/src/interfaces.cpp +++ b/src/interfaces.cpp @@ -1616,8 +1616,6 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS) std::string filterScript = gFilterScript; if(authorized && !argFilterScript.empty()) filterScript = argFilterScript; - if(startsWith(filterScript, "path:")) - filterScript = fileGet(filterScript.substr(5), false); if(filterScript.size()) { if(startsWith(filterScript, "path:"))