Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ public class GitUtils {
/**
* Pattern for validating the ssh address if it strictly doesn't start with a scheme
* username can start with any small alphabet or a _ underscore
* hostname can have all alphanumerics, -, and . e.g. ssh://_ab-xy@ab-12.ab:/v3/newJet/ai/zilla.git
* the port number could be not present as well. e.g. ssh://_ab-xy@domain.com:/v3/newJet/ai/zilla
* hostname can have all alphanumerics, -, and . e.g. _ab-xy@ab-12.ab:v3/newJet/ai/zilla.git
* Optional custom port is supported as user@host:port/path (e.g. git@host:2222/user/repo.git).
* A leading numeric path segment followed by '/' is treated as a port, matching common
* non-standard SCP-style URLs; such numeric namespaces are extremely rare in practice.
* The captured port is not included in the HTTPS conversion (same as URL_PATTERN_WITH_SCHEME).
*/
public static final Pattern URL_PATTERN_WITHOUT_SCHEME =
Pattern.compile("^[a-z_][\\w-]+@(?<host>[\\w-.]+):/*(?<path>.+?)(\\.git)?$");
Pattern.compile("^[a-z_][\\w-]+@(?<host>[\\w-.]+):(?:(?<port>\\d+)/)?/*(?<path>.+?)(\\.git)?$");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

/**
* Sample repo urls :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void convertSshUrlToBrowserSupportedUrl() {
assertThat(GitUtils.convertSshUrlToBrowserSupportedUrl("git@absolute.path.com:/test/newRepo.git"))
.isEqualTo("https://absolute.path.com/test/newRepo");

// Custom SSH port:
// Custom SSH port (ssh:// scheme — port must not become part of the HTTPS path):
assertThat(GitUtils.convertSshUrlToBrowserSupportedUrl(
"ssh://git@example.test.net:1234/user/test/tests/testRepo.git"))
.isEqualTo("https://example.test.net/user/test/tests/testRepo");
Expand All @@ -68,6 +68,16 @@ public void convertSshUrlToBrowserSupportedUrl() {
"ssh://git@tim.tam.example.com:9876/v3/sladeping/pyhe/SpaceJunk"))
.isEqualTo("https://tim.tam.example.com/v3/sladeping/pyhe/SpaceJunk");

// Custom SSH port (SCP-like form user@host:port/path — same HTTPS result as ssh://):
assertThat(GitUtils.convertSshUrlToBrowserSupportedUrl(
"git@example.test.net:2222/user/test/tests/testRepo.git"))
.isEqualTo("https://example.test.net/user/test/tests/testRepo");
assertThat(GitUtils.convertSshUrlToBrowserSupportedUrl("git@example.com:443/test/testRepo.git"))
.isEqualTo("https://example.com/test/testRepo");
assertThat(GitUtils.convertSshUrlToBrowserSupportedUrl(
"git@tim.tam.example.com:5678/v3/sladeping/pyhe/SpaceJunk"))
.isEqualTo("https://tim.tam.example.com/v3/sladeping/pyhe/SpaceJunk");

// custom ssh username:
assertThat(GitUtils.convertSshUrlToBrowserSupportedUrl("abc-xy@vs-ssh.visualstudio.com:v3/newJet/ai/zilla"))
.isEqualTo("https://vs-ssh.visualstudio.com/v3/newJet/ai/zilla");
Expand Down