@Test @SuppressLint("AuthLeak") public void testStripUserInfo() { assertEquals("", UrlUtils.stripUserInfo(null)); assertEquals("", UrlUtils.stripUserInfo("")); assertEquals("https: assertEquals("https: assertEquals("user@mozilla.org", UrlUtils.stripUserInfo("user@mozilla.org")); assertEquals("ftp: assertEquals("öäü102ß", UrlUtils.stripUserInfo("öäü102ß")); }
public static String stripUserInfo(@Nullable String url) { if (TextUtils.isEmpty(url)) { return ""; } try { URI uri = new URI(url); final String userInfo = uri.getUserInfo(); if (userInfo == null) { return url; } uri = new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); return uri.toString(); } catch (URISyntaxException e) { return url; } }
UrlUtils { public static String stripUserInfo(@Nullable String url) { if (TextUtils.isEmpty(url)) { return ""; } try { URI uri = new URI(url); final String userInfo = uri.getUserInfo(); if (userInfo == null) { return url; } uri = new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); return uri.toString(); } catch (URISyntaxException e) { return url; } } }
UrlUtils { public static String stripUserInfo(@Nullable String url) { if (TextUtils.isEmpty(url)) { return ""; } try { URI uri = new URI(url); final String userInfo = uri.getUserInfo(); if (userInfo == null) { return url; } uri = new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); return uri.toString(); } catch (URISyntaxException e) { return url; } }  }
UrlUtils { public static String stripUserInfo(@Nullable String url) { if (TextUtils.isEmpty(url)) { return ""; } try { URI uri = new URI(url); final String userInfo = uri.getUserInfo(); if (userInfo == null) { return url; } uri = new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); return uri.toString(); } catch (URISyntaxException e) { return url; } }  static String normalize(@NonNull String input); static boolean isUrl(String url); static boolean isValidSearchQueryUrl(String url); static boolean isHttpOrHttps(String url); static String createSearchUrl(Context context, String searchTerm); static String stripUserInfo(@Nullable String url); static boolean isPermittedResourceProtocol(@Nullable final String scheme); static boolean isSupportedProtocol(@Nullable final String scheme); static boolean isInternalErrorURL(final String url); static boolean urlsMatchExceptForTrailingSlash(final String url1, final String url2); static String stripCommonSubdomains(@Nullable String host); static String stripScheme(@Nullable String url); static String stripSchemeAndSubDomain(String url); static boolean isLocalizedContent(@Nullable String url); }
UrlUtils { public static String stripUserInfo(@Nullable String url) { if (TextUtils.isEmpty(url)) { return ""; } try { URI uri = new URI(url); final String userInfo = uri.getUserInfo(); if (userInfo == null) { return url; } uri = new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); return uri.toString(); } catch (URISyntaxException e) { return url; } }  static String normalize(@NonNull String input); static boolean isUrl(String url); static boolean isValidSearchQueryUrl(String url); static boolean isHttpOrHttps(String url); static String createSearchUrl(Context context, String searchTerm); static String stripUserInfo(@Nullable String url); static boolean isPermittedResourceProtocol(@Nullable final String scheme); static boolean isSupportedProtocol(@Nullable final String scheme); static boolean isInternalErrorURL(final String url); static boolean urlsMatchExceptForTrailingSlash(final String url1, final String url2); static String stripCommonSubdomains(@Nullable String host); static String stripScheme(@Nullable String url); static String stripSchemeAndSubDomain(String url); static boolean isLocalizedContent(@Nullable String url);  }