File tree Expand file tree Collapse file tree 4 files changed +18
-15
lines changed Expand file tree Collapse file tree 4 files changed +18
-15
lines changed Original file line number Diff line number Diff line change @@ -168,8 +168,6 @@ struct GitInputScheme : InputScheme
168168 return {};
169169
170170 auto url2 (url);
171- if (hasPrefix (url2.scheme , " git+" ))
172- url2.scheme = std::string (url2.scheme , 4 );
173171 url2.query .clear ();
174172
175173 Attrs attrs;
Original file line number Diff line number Diff line change @@ -35,10 +35,10 @@ INSTANTIATE_TEST_SUITE_P(
3535 // Already proper URL with git+ssh
3636 FixGitURLParam{
3737 .input = " git+ssh://user@domain:1234/path" ,
38- .expected = " git+ ssh://user@domain:1234/path" ,
38+ .expected = " ssh://user@domain:1234/path" ,
3939 .parsed =
4040 ParsedURL{
41- .scheme = " git+ ssh" ,
41+ .scheme = " ssh" ,
4242 .authority =
4343 ParsedURL::Authority{
4444 .host = " domain" ,
Original file line number Diff line number Diff line change @@ -330,10 +330,13 @@ struct ParsedUrlScheme
330330
331331ParsedUrlScheme parseUrlScheme (std::string_view scheme);
332332
333- /* Detects scp-style uris (e.g. [email protected] :NixOS/nix) and fixes334- them by removing the `:` and assuming a scheme of `ssh://`. Also
335- changes absolute paths into file:// URLs. */
336- ParsedURL fixGitURL (const std::string & url);
333+ /* *
334+ * Detects scp-style uris (e.g. `[email protected] :NixOS/nix`) and fixes 335+ * them by removing the `:` and assuming a scheme of `ssh://`. Also
336+ * drops `git+` from the scheme (e.g. `git+https://` to `https://`)
337+ * and changes absolute paths into `file://` URLs.
338+ */
339+ ParsedURL fixGitURL (std::string url);
337340
338341/* *
339342 * Whether a string is valid as RFC 3986 scheme name.
Original file line number Diff line number Diff line change @@ -409,21 +409,23 @@ ParsedUrlScheme parseUrlScheme(std::string_view scheme)
409409 };
410410}
411411
412- ParsedURL fixGitURL (const std::string & url)
412+ ParsedURL fixGitURL (std::string url)
413413{
414414 std::regex scpRegex (" ([^/]*)@(.*):(.*)" );
415415 if (!hasPrefix (url, " /" ) && std::regex_match (url, scpRegex))
416- return parseURL (std::regex_replace (url, scpRegex, " ssh://$1@$2/$3" ));
417- if (hasPrefix (url, " file:" ))
418- return parseURL (url);
419- if (url.find (" ://" ) == std::string::npos) {
416+ url = std::regex_replace (url, scpRegex, " ssh://$1@$2/$3" );
417+ if (!hasPrefix (url, " file:" ) && !hasPrefix (url, " git+file:" ) && url.find (" ://" ) == std::string::npos)
420418 return ParsedURL{
421419 .scheme = " file" ,
422420 .authority = ParsedURL::Authority{},
423421 .path = splitString<std::vector<std::string>>(url, " /" ),
424422 };
425- }
426- return parseURL (url);
423+ auto parsed = parseURL (url);
424+ // Drop the superfluous "git+" from the scheme.
425+ auto scheme = parseUrlScheme (parsed.scheme );
426+ if (scheme.application == " git" )
427+ parsed.scheme = scheme.transport ;
428+ return parsed;
427429}
428430
429431// https://www.rfc-editor.org/rfc/rfc3986#section-3.1
You can’t perform that action at this time.
0 commit comments