public static void _testAllowFileScheme(boolean allow) { if (allow) { uriSchemeWhitelist.add("file"); // $NON-NLS-1$ } else { uriSchemeWhitelist.remove("file"); // $NON-NLS-1$ } }
/** * Returns whether or not the git repository URI is forbidden. If a scheme of the URI is matched, * check if the scheme is a supported protocol. Otherwise, match for a scp-like ssh URI: * [user@]host.xz:path/to/repo.git/ and ensure the URI does not represent a local file path. * * @param uri A git repository URI * @return a boolean of whether or not the git repository URI is forbidden. */ public static boolean isForbiddenGitUri(URIish uri) { String scheme = uri.getScheme(); String host = uri.getHost(); String path = uri.getPath(); boolean isForbidden = false; if (scheme != null) { isForbidden = !uriSchemeWhitelist.contains(scheme); } else { // match for a scp-like ssh URI if (host != null) { isForbidden = host.length() == 1 || path == null; } else { isForbidden = true; } } return isForbidden; }