URLUtil { @NotNull public static String parseHostFromSshUrl(@NotNull String sshUrl) { String host = sshUrl; int at = host.lastIndexOf('@'); if (at > 0) { host = host.substring(at + 1); } else { int firstColon = host.indexOf(':'); if (firstColon > 0) { host = host.substring(firstColon + 3); } } int colon = host.indexOf(':'); if (colon > 0) { host = host.substring(0, colon); } else { int slash = host.indexOf('/'); if (slash > 0) { host = host.substring(0, slash); } } return host; } private  URLUtil(); @NotNull static InputStream openStream(@NotNull URL url); @NotNull static InputStream openResourceStream(@NotNull URL url); @Nullable static Pair<String, String> splitJarUrl(@NotNull String url); @NotNull static String unescapePercentSequences(@NotNull String s); static boolean containsScheme(@NotNull String url); static boolean isDataUri(@NotNull String value); @Nullable static byte[] getBytesFromDataUri(@NotNull String dataUrl); @NotNull static String parseHostFromSshUrl(@NotNull String sshUrl); static final String SCHEME_SEPARATOR; static final String FILE_PROTOCOL; static final String HTTP_PROTOCOL; static final String JAR_PROTOCOL; static final String JAR_SEPARATOR; static final Pattern DATA_URI_PATTERN; static final Pattern URL_PATTERN; }
@Test public void testParseHostFromSshUrl() { String[] SSH_URL_VARIANTS = { "git@github.com", "git@github.com/project.git", "ssh: "ssh: "git@github.com:project.git", "ssh: "ssh: "user@name@github.com:project.git", "git@github.com/company/user/project.git", "git@github.com:company/user/project.git", "git@github.com:3128:user/project.git" }; for (String sshUrl : SSH_URL_VARIANTS) { assertEquals("github.com", URLUtil.parseHostFromSshUrl(sshUrl)); } }