mirror of
https://github.com/NixOS/nix.git
synced 2024-11-21 22:32:26 +00:00
Fix the parsing of path flake refs with a query
`/path?foo=bar` was parsed as `/path`, omitting the query altogether (`/path?foo=bar#` was parsed correctly though). Rewrite the path flake ref parser to fix this
This commit is contained in:
parent
fbf3f9398a
commit
3740cdb654
@ -78,19 +78,25 @@ std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
|
|||||||
std::string path = url;
|
std::string path = url;
|
||||||
std::string fragment = "";
|
std::string fragment = "";
|
||||||
std::map<std::string, std::string> query;
|
std::map<std::string, std::string> query;
|
||||||
auto pathEnd = url.find_first_of("#?");
|
auto pathEnd = url.find_first_of("?#");
|
||||||
auto fragmentStart = pathEnd;
|
|
||||||
if (pathEnd != std::string::npos && url[pathEnd] == '?') {
|
|
||||||
fragmentStart = url.find("#");
|
|
||||||
}
|
|
||||||
if (pathEnd != std::string::npos) {
|
if (pathEnd != std::string::npos) {
|
||||||
|
// There's something (either a query string or a fragment) in addition
|
||||||
|
// to the path
|
||||||
path = url.substr(0, pathEnd);
|
path = url.substr(0, pathEnd);
|
||||||
}
|
std::string non_path_part = url.substr(pathEnd + 1);
|
||||||
if (fragmentStart != std::string::npos) {
|
if (url[pathEnd] == '#') {
|
||||||
fragment = percentDecode(url.substr(fragmentStart+1));
|
// Not query, just a fragment
|
||||||
}
|
fragment = percentDecode(non_path_part);
|
||||||
if (pathEnd != std::string::npos && fragmentStart != std::string::npos) {
|
} else {
|
||||||
query = decodeQuery(url.substr(pathEnd+1, fragmentStart-pathEnd-1));
|
// We have a query, and maybe a fragment too
|
||||||
|
auto fragmentStart = non_path_part.find("#");
|
||||||
|
if (fragmentStart != std::string::npos) {
|
||||||
|
query = decodeQuery(non_path_part.substr(0, fragmentStart));
|
||||||
|
fragment = percentDecode(non_path_part.substr(fragmentStart+1));
|
||||||
|
} else {
|
||||||
|
query = decodeQuery(non_path_part);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (baseDir) {
|
if (baseDir) {
|
||||||
|
@ -24,7 +24,7 @@ test_subdir_self_path() {
|
|||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
(
|
(
|
||||||
nix build $baseDir?dir=b-low --no-link
|
nix build $baseDir/b-low --no-link
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
test_subdir_self_path
|
test_subdir_self_path
|
||||||
|
Loading…
Reference in New Issue
Block a user