diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2021-01-18 12:55:06 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2021-01-18 12:55:06 +0100 |
commit | 1bbc66f8650150898f8d8e3c8c86f3b27802e019 (patch) | |
tree | b30f262f0d42a9f5f3abd8e33a8a5e3f841d0e85 /src/libfetchers | |
parent | f0b9a3c9748b2cbd7b3be6814a78abc2bedf62e8 (diff) | |
parent | 59f2dd8e8da1f82aa9e29e30ba1df643434a9254 (diff) |
Merge branch 'slashes-in-github-branches' of https://github.com/Ma27/nix
Diffstat (limited to 'src/libfetchers')
-rw-r--r-- | src/libfetchers/github.cc | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc index db1ced5d6..8352ef02d 100644 --- a/src/libfetchers/github.cc +++ b/src/libfetchers/github.cc @@ -37,15 +37,29 @@ struct GitArchiveInputScheme : InputScheme std::optional<std::string> ref; std::optional<std::string> host_url; - if (path.size() == 2) { - } else if (path.size() == 3) { + auto size = path.size(); + if (size == 3) { if (std::regex_match(path[2], revRegex)) rev = Hash::parseAny(path[2], htSHA1); else if (std::regex_match(path[2], refRegex)) ref = path[2]; else throw BadURL("in URL '%s', '%s' is not a commit hash or branch/tag name", url.url, path[2]); - } else + } else if (size > 3) { + std::string rs; + for (auto i = std::next(path.begin(), 2); i != path.end(); i++) { + rs += *i; + if (std::next(i) != path.end()) { + rs += "/"; + } + } + + if (std::regex_match(rs, refRegex)) { + ref = rs; + } else { + throw BadURL("in URL '%s', '%s' is not a branch/tag name", url.url, rs); + } + } else if (size < 2) throw BadURL("URL '%s' is invalid", url.url); for (auto &[name, value] : url.query) { |