mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-29 00:46:17 +02:00
Fix config password parsing
This commit is contained in:
parent
7d7ef5bf10
commit
aa3b289b47
4 changed files with 52 additions and 4 deletions
|
@ -140,7 +140,7 @@ std::string uriDecode(const std::string& src)
|
|||
if (int(src[i]) == 37)
|
||||
{
|
||||
unsigned int ii;
|
||||
sscanf(src.substr(i + 1, 2).c_str(), "%x", &ii);
|
||||
sscanf(src.substr(i + 1, 2).c_str(), "%x", &ii); // NOLINT
|
||||
ch = static_cast<char>(ii);
|
||||
ret += ch;
|
||||
i += 2;
|
||||
|
@ -170,6 +170,22 @@ void split_left(const std::string& s, char delim, std::string& left, std::string
|
|||
}
|
||||
|
||||
|
||||
void split_right(const std::string& s, char delim, std::string& left, std::string& right)
|
||||
{
|
||||
auto pos = s.rfind(delim);
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
left = s.substr(0, pos);
|
||||
right = s.substr(pos + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
left = s;
|
||||
right = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string split_left(const std::string& s, char delim, std::string& right)
|
||||
{
|
||||
std::string left;
|
||||
|
@ -178,6 +194,14 @@ std::string split_left(const std::string& s, char delim, std::string& right)
|
|||
}
|
||||
|
||||
|
||||
std::string split_right(const std::string& s, char delim, std::string& right)
|
||||
{
|
||||
std::string left;
|
||||
split_right(s, delim, left, right);
|
||||
return left;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<std::string>& split(const std::string& s, char delim, std::vector<std::string>& elems)
|
||||
{
|
||||
|
|
|
@ -57,13 +57,20 @@ std::string uriDecode(const std::string& src);
|
|||
/// @return uri encoded version of @p str
|
||||
std::string urlEncode(const std::string& str);
|
||||
|
||||
/// Split string @p s at @p delim into @p left and @p right
|
||||
/// Split string @p s at left-most @p delim into @p left and @p right
|
||||
void split_left(const std::string& s, char delim, std::string& left, std::string& right);
|
||||
|
||||
/// Split string @p s at @p delim and left and @p right
|
||||
/// Split string @p s at right-most @p delim into @p left and @p right
|
||||
void split_right(const std::string& s, char delim, std::string& left, std::string& right);
|
||||
|
||||
/// Split string @p s at left-most @p delim into left and @p right
|
||||
/// @return the left part
|
||||
std::string split_left(const std::string& s, char delim, std::string& right);
|
||||
|
||||
/// Split string @p s at right-most @p delim into left and @p right
|
||||
/// @return the left part
|
||||
std::string split_right(const std::string& s, char delim, std::string& right);
|
||||
|
||||
/// Split string @p s at @p delim and return the splitted list in @p elems
|
||||
/// @return list of splitted strings
|
||||
std::vector<std::string>& split(const std::string& s, char delim, std::vector<std::string>& elems);
|
||||
|
|
|
@ -99,7 +99,7 @@ struct ServerSettings
|
|||
{
|
||||
std::string perm;
|
||||
name = utils::string::split_left(user_password_role, ':', perm);
|
||||
password = utils::string::split_left(perm, ':', role_name);
|
||||
password = utils::string::split_right(perm, ':', role_name);
|
||||
}
|
||||
|
||||
/// user name
|
||||
|
|
|
@ -84,6 +84,23 @@ TEST_CASE("String utils")
|
|||
|
||||
std::vector<std::string> vec{"1", "2", "3"};
|
||||
REQUIRE(container_to_string(vec) == "1, 2, 3");
|
||||
|
||||
std::string right;
|
||||
std::string left = split_left("left:mid:right", ':', right);
|
||||
REQUIRE(left == "left");
|
||||
REQUIRE(right == "mid:right");
|
||||
|
||||
left = split_right("left:mid:right", ':', right);
|
||||
REQUIRE(left == "left:mid");
|
||||
REQUIRE(right == "right");
|
||||
|
||||
std::string user = split_left("username:password:with:colons:role", ':', right);
|
||||
REQUIRE(user == "username");
|
||||
REQUIRE(right == "password:with:colons:role");
|
||||
std::string role;
|
||||
std::string password = split_right(right, ':', role);
|
||||
REQUIRE(password == "password:with:colons");
|
||||
REQUIRE(role == "role");
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue