Skip to content

Commit

Permalink
Enhancements
Browse files Browse the repository at this point in the history
Add validation of exclude/include values passed from URI argument.
Update pref.ini.
  • Loading branch information
tindy2013 committed Dec 3, 2019
1 parent 4057d7e commit 6079487
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
std::vector<nodeInfo> nodes;
int groupID = 0;

if(include.size())
if(include.size() && regValid(include))
include_remarks.emplace_back(include);
else
include_remarks = def_include_remarks;
if(exclude.size())
if(exclude.size() && regValid(exclude))
exclude_remarks.emplace_back(exclude);
else
exclude_remarks = def_exclude_remarks;
Expand Down
13 changes: 13 additions & 0 deletions misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,19 @@ std::string replace_all_distinct(std::string str, std::string old_value, std::st
return str;
}

bool regValid(std::string &reg)
{
try
{
std::regex r(reg);
return true;
}
catch (std::regex_error &e)
{
return false;
}
}

bool regFind(std::string src, std::string target)
{
try
Expand Down
1 change: 1 addition & 0 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ bool is_str_utf8(std::string data);
std::string getFormData(const std::string &raw_data);

void sleep(int interval);
bool regValid(std::string &reg);
bool regFind(std::string src, std::string target);
std::string regReplace(std::string src, std::string match, std::string rep);
bool regMatch(std::string src, std::string match);
Expand Down
5 changes: 4 additions & 1 deletion pref.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ api_mode=false
default_url=

;Exclude nodes which remarks match the following patterns. Supports regular expression.
exclude_remarks=(流量|时间|官网|产品)
exclude_remarks=(到期|流量|时间|官网|产品)
;exclude_remarks=(other rule)

;Only include nodes which remarks match the following patterns. Supports regular expression.
Expand Down Expand Up @@ -93,6 +93,9 @@ write_managed_config=true
;Address prefix for MANAGED-CONFIG info, without the trailing "/".
managed_config_prefix=http://127.0.0.1:25500

[surge_external_proxy]
;surge_ssr_path=/usr/bin/ssr-local

[emojis]
add_emoji=true
remove_old_emoji=true
Expand Down

0 comments on commit 6079487

Please sign in to comment.