1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 10:50:24 -04:00

fix: warn on malformed URI query parameter

This commit is contained in:
Bryan Honof 2024-09-12 00:20:17 +02:00
parent 48477d4a3e
commit f53b144155
No known key found for this signature in database
2 changed files with 9 additions and 5 deletions

View file

@ -88,7 +88,7 @@ std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
if (fragmentStart != std::string::npos) { if (fragmentStart != std::string::npos) {
fragment = percentDecode(url.substr(fragmentStart+1)); fragment = percentDecode(url.substr(fragmentStart+1));
} }
if (pathEnd != std::string::npos && fragmentStart != std::string::npos) { if (pathEnd != std::string::npos && fragmentStart != std::string::npos && url[pathEnd] == '?') {
query = decodeQuery(url.substr(pathEnd+1, fragmentStart-pathEnd-1)); query = decodeQuery(url.substr(pathEnd+1, fragmentStart-pathEnd-1));
} }

View file

@ -79,10 +79,14 @@ std::map<std::string, std::string> decodeQuery(const std::string & query)
for (auto s : tokenizeString<Strings>(query, "&")) { for (auto s : tokenizeString<Strings>(query, "&")) {
auto e = s.find('='); auto e = s.find('=');
if (e != std::string::npos) if (e == std::string::npos) {
result.emplace( warn("dubious URI query '%s' is missing equal sign '%s'", s, "=");
s.substr(0, e), continue;
percentDecode(std::string_view(s).substr(e + 1))); }
result.emplace(
s.substr(0, e),
percentDecode(std::string_view(s).substr(e + 1)));
} }
return result; return result;