Skip to content

Commit

Permalink
fix: warn on malformed URI query parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanhonof committed Sep 11, 2024
1 parent 48477d4 commit f53b144
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/libflake/flake/flakeref.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
if (fragmentStart != std::string::npos) {
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));
}

Expand Down
12 changes: 8 additions & 4 deletions src/libutil/url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,14 @@ std::map<std::string, std::string> decodeQuery(const std::string & query)

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

result.emplace(
s.substr(0, e),
percentDecode(std::string_view(s).substr(e + 1)));
}

return result;
Expand Down

0 comments on commit f53b144

Please sign in to comment.