8000 Fix password parsing for SS2022 with special characters by iCasture · Pull Request #849 · tindy2013/subconverter · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix password parsing for SS2022 with special characters #849

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
38 changes: 19 additions & 19 deletions src/parser/subparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void hysteriaConstruct(
if (!up.empty())
{
if (up.length() > 4 && up.find("bps") == up.length() - 3)

node.Up = up;
else if (to_int(up))
{
Expand Down Expand Up @@ -209,13 +209,13 @@ void hysteriaConstruct(
}

void hysteria2Construct(
Proxy &node,
Proxy &node,
const std::string &group,
const std::string &remarks,
const std::string &server,
const std::string &server,
const std::string &port,
const std::string &ports,
const std::string &up,
const std::string &up,
const std::string &down,
const std::string &password,
const std::string &obfs,
Expand All @@ -226,9 +226,9 @@ void hysteria2Construct(
const std::string &ca,
const std::string &caStr,
const std::string &cwnd,
const std::string &hop_interval,
tribool tfo,
tribool scv,
const std::string &hop_interval,
tribool tfo,
tribool scv,
const std::string &underlying_proxy
) {
commonConstruct(node, ProxyType::Hysteria2, group, remarks, server, port, tribool(), tfo, scv, tribool(), underlying_proxy);
Expand Down Expand Up @@ -1352,7 +1352,7 @@ void explodeClash(Node yamlnode, std::vector<Proxy> &nodes)
singleproxy["down"] >>= down;
singleproxy["password"] >>= password;
if (password.empty())
singleproxy["auth"] >>= password;
singleproxy["auth"] >>= password;
singleproxy["obfs"] >>= obfs;
singleproxy["obfs-password"] >>= obfs_password;
singleproxy["sni"] >>= sni;
Expand Down Expand Up @@ -1728,7 +1728,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)

for(i = 3; i < configs.size(); i++)
{
vArray = split(configs[i], "=");
vArray = splitKeyValue(configs[i], "=");
if(vArray.size() < 2)
continue;
itemName = trim(vArray[0]);
Expand Down Expand Up @@ -1778,7 +1778,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
}
for(i = 5; i < configs.size(); i++)
{
vArray = split(configs[i], "=");
vArray = splitKeyValue(configs[i], "=");
if(vArray.size() < 2)
continue;
itemName = trim(vArray[0]);
Expand Down Expand Up @@ -1810,7 +1810,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)

for(i = 3; i < configs.size(); i++)
{
vArray = split(configs[i], "=");
vArray = splitKeyValue(configs[i], "=");
if(vArray.size() != 2)
continue;
itemName = trim(vArray[0]);
Expand Down Expand Up @@ -1873,7 +1873,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
continue;
for(i = 3; i < configs.size(); i++)
{
vArray = split(configs[i], "=");
vArray = splitKeyValue(configs[i], "=");
if(vArray.size() < 2)
continue;
itemName = trim(vArray[0]);
Expand Down Expand Up @@ -1903,7 +1903,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)

for(i = 3; i < configs.size(); i++)
{
vArray = split(configs[i], "=");
vArray = splitKeyValue(configs[i], "=");
if(vArray.size() != 2)
continue;
itemName = trim(vArray[0]);
Expand Down Expand Up @@ -1940,7 +1940,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)

for(i = 3; i < configs.size(); i++)
{
vArray = split(configs[i], "=");
vArray = splitKeyValue(configs[i], "=");
if(vArray.size() != 2)
continue;
itemName = trim(vArray[0]);
Expand Down Expand Up @@ -1978,7 +1978,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
case "wireguard"_hash:
for (i = 1; i < configs.size(); i++)
{
vArray = split(trim(configs[i]), "=");
vArray = splitKeyValue(trim(configs[i]), "=");
if(vArray.size() != 2)
continue;
itemName = trim(vArray[0]);
Expand Down Expand Up @@ -2045,7 +2045,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)

for(i = 1; i < configs.size(); i++)
{
vArray = split(trim(configs[i]), "=");
vArray = splitKeyValue(trim(configs[i]), "=");
if(vArray.size() != 2)
continue;
itemName = trim(vArray[0]);
Expand Down Expand Up @@ -2146,7 +2146,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)

for(i = 1; i < configs.size(); i++)
{
vArray = split(trim(configs[i]), "=");
vArray = splitKeyValue(trim(configs[i]), "=");
if(vArray.size() != 2)
continue;
itemName = trim(vArray[0]);
Expand Down Expand Up @@ -2214,7 +2214,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)

for(i = 1; i < configs.size(); i++)
{
vArray = split(trim(configs[i]), "=");
vArray = splitKeyValue(trim(configs[i]), "=");
if(vArray.size() != 2)
continue;
itemName = trim(vArray[0]);
Expand Down Expand Up @@ -2262,7 +2262,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)

for(i = 1; i < configs.size(); i++)
{
vArray = split(trim(configs[i]), "=");
vArray = splitKeyValue(trim(configs[i]), "=");
if(vArray.size() != 2)
continue;
itemName = trim(vArray[0]);
Expand Down
28 changes: 28 additions & 0 deletions src/utils/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,34 @@ std::vector<std::string_view> split(std::string_view s, char separator)
return result;
}

/**
* Split string at the first occurrence of separator only.
*
* This function is designed for parsing key-value pairs where the value
* may contain the separator character. For example, in SS2022 protocol,
* the password field may contain '=' characters that should not be treated
* as additional separators.
*/
std::vector<std::string> splitKeyValue(const std::string &s, const std::string &separator)
{
std::vector<std::string> result;
string_size pos = s.find(separator);

if (pos == std::string::npos)
{
// No separator found, return the whole string
result.push_back(s);
}
else
{
// Split only at the first occurrence of separator
result.push_back(s.substr(0, pos));
result.push_back(s.substr(pos + separator.size()));
}

return result;
}

std::string UTF8ToCodePoint(const std::string &data)
{
std::stringstream ss;
Expand Down
2 changes: 2 additions & 0 deletions src/utils/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ using string_pair_array = std::vector<std::pair<std::string, std::string>>;
std::vector<std::string> split(const std::string &s, const std::string &separator);
std::vector<std::string_view> split(std::string_view s, char separator);
void split(std::vector<std::string_view> &result, std::string_view s, char separator);
// Split string at first separator only, useful for key-value pairs where value may contain separator
std::vector<std::string> splitKeyValue(const std::string &s, const std::string &separator);
std::string join(const string_array &arr, const std::string &delimiter);

template <typename InputIt>
Expand Down
0