From 6d46b5b609f8f85968e1ca7aaf7c57dd52d0521c Mon Sep 17 00:00:00 2001 From: Kalle Jepsen Date: Wed, 17 Nov 2021 08:41:26 +0100 Subject: [PATCH 1/2] Fix detection of scp-style URIs to support non-standard SSH ports for git --- src/libexpr/primops/fetchTree.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libexpr/primops/fetchTree.cc b/src/libexpr/primops/fetchTree.cc index e6becdafc..b307ac04a 100644 --- a/src/libexpr/primops/fetchTree.cc +++ b/src/libexpr/primops/fetchTree.cc @@ -74,8 +74,11 @@ std::string fixURI(std::string uri, EvalState & state, const std::string & defau std::string fixURIForGit(std::string uri, EvalState & state) { + /* Detects scp-style uris (e.g. git@github.com:NixOS/nix) and fixes + * them by removing the `:` and assuming a scheme of `ssh://` + * */ static std::regex scp_uri("([^/].*)@(.*):(.*)"); - if (uri[0] != '/' && std::regex_match(uri, scp_uri)) + if (uri[0] != '/' && std::regex_match(uri, scp_uri) && uri.find("://") == std::string::npos) return fixURI(std::regex_replace(uri, scp_uri, "$1@$2/$3"), state, "ssh"); else return fixURI(uri, state); From 46d2a5a10be7e48679a29d487adbb6f1d6fd452a Mon Sep 17 00:00:00 2001 From: Kalle Jepsen Date: Wed, 17 Nov 2021 13:49:10 +0100 Subject: [PATCH 2/2] Simplify fix by disallowing / in front of @ to match scp style --- src/libexpr/primops/fetchTree.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libexpr/primops/fetchTree.cc b/src/libexpr/primops/fetchTree.cc index b307ac04a..079513873 100644 --- a/src/libexpr/primops/fetchTree.cc +++ b/src/libexpr/primops/fetchTree.cc @@ -77,8 +77,8 @@ std::string fixURIForGit(std::string uri, EvalState & state) /* Detects scp-style uris (e.g. git@github.com:NixOS/nix) and fixes * them by removing the `:` and assuming a scheme of `ssh://` * */ - static std::regex scp_uri("([^/].*)@(.*):(.*)"); - if (uri[0] != '/' && std::regex_match(uri, scp_uri) && uri.find("://") == std::string::npos) + static std::regex scp_uri("([^/]*)@(.*):(.*)"); + if (uri[0] != '/' && std::regex_match(uri, scp_uri)) return fixURI(std::regex_replace(uri, scp_uri, "$1@$2/$3"), state, "ssh"); else return fixURI(uri, state);