mirror of
https://github.com/badaix/snapcast.git
synced 2025-07-25 20:38:55 +02:00
decode percent encoded URIs
This commit is contained in:
parent
cf628bfcd6
commit
538352fbf2
4 changed files with 31 additions and 8 deletions
|
@ -81,6 +81,29 @@ static inline std::string trim_copy(const std::string &s)
|
||||||
return trim(str);
|
return trim(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// decode %xx to char
|
||||||
|
static std::string uriDecode(const std::string& src) {
|
||||||
|
std::string ret;
|
||||||
|
char ch;
|
||||||
|
for (size_t i=0; i<src.length(); i++)
|
||||||
|
{
|
||||||
|
if (int(src[i]) == 37)
|
||||||
|
{
|
||||||
|
unsigned int ii;
|
||||||
|
sscanf(src.substr(i+1, 2).c_str(), "%x", &ii);
|
||||||
|
ch = static_cast<char>(ii);
|
||||||
|
ret += ch;
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret += src[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems)
|
static std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems)
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,8 +33,9 @@ ReaderUri::ReaderUri(const std::string& uri)
|
||||||
// would be more elegant with regex. Not yet supported on my dev machine's gcc 4.8 :(
|
// would be more elegant with regex. Not yet supported on my dev machine's gcc 4.8 :(
|
||||||
size_t pos;
|
size_t pos;
|
||||||
this->uri = uri;
|
this->uri = uri;
|
||||||
|
string decodedUri = uriDecode(uri);
|
||||||
|
|
||||||
id_ = uri;
|
id_ = decodedUri;
|
||||||
pos = id_.find('?');
|
pos = id_.find('?');
|
||||||
if (pos != string::npos)
|
if (pos != string::npos)
|
||||||
id_ = id_.substr(0, pos);
|
id_ = id_.substr(0, pos);
|
||||||
|
@ -43,7 +44,7 @@ ReaderUri::ReaderUri(const std::string& uri)
|
||||||
id_ = id_.substr(0, pos);
|
id_ = id_.substr(0, pos);
|
||||||
logD << "id: '" << id_ << "'\n";
|
logD << "id: '" << id_ << "'\n";
|
||||||
|
|
||||||
string tmp(uri);
|
string tmp(decodedUri);
|
||||||
|
|
||||||
pos = tmp.find(':');
|
pos = tmp.find(':');
|
||||||
if (pos == string::npos)
|
if (pos == string::npos)
|
||||||
|
|
|
@ -50,7 +50,6 @@ struct ReaderUri
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string id_;
|
std::string id_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue