diff --git a/src/libexpr/flake/flakeref.cc b/src/libexpr/flake/flakeref.cc index 4fff0f905..a43356cba 100644 --- a/src/libexpr/flake/flakeref.cc +++ b/src/libexpr/flake/flakeref.cc @@ -78,19 +78,25 @@ std::pair parsePathFlakeRefWithFragment( std::string path = url; std::string fragment = ""; std::map query; - auto pathEnd = url.find_first_of("#?"); - auto fragmentStart = pathEnd; - if (pathEnd != std::string::npos && url[pathEnd] == '?') { - fragmentStart = url.find("#"); - } + auto pathEnd = url.find_first_of("?#"); 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); - } - if (fragmentStart != std::string::npos) { - fragment = percentDecode(url.substr(fragmentStart+1)); - } - if (pathEnd != std::string::npos && fragmentStart != std::string::npos) { - query = decodeQuery(url.substr(pathEnd+1, fragmentStart-pathEnd-1)); + std::string non_path_part = url.substr(pathEnd + 1); + if (url[pathEnd] == '#') { + // Not query, just a fragment + fragment = percentDecode(non_path_part); + } else { + // 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) { diff --git a/tests/functional/flakes/inputs.sh b/tests/functional/flakes/inputs.sh index 80620488a..f9324e8f1 100644 --- a/tests/functional/flakes/inputs.sh +++ b/tests/functional/flakes/inputs.sh @@ -24,7 +24,7 @@ test_subdir_self_path() { } EOF ( - nix build $baseDir?dir=b-low --no-link + nix build $baseDir/b-low --no-link ) } test_subdir_self_path