MCPcopy Index your code
hub / github.com/HtmlUnit/htmlunit / toUrlUnsafe

Method toUrlUnsafe

src/main/java/org/htmlunit/util/UrlUtils.java:230–260  ·  view source on GitHub ↗

Constructs a URL instance based on the specified URL string, taking into account the fact that the specified URL string may represent an "about:..." URL, a "javascript:..." URL, or a data:... URL. Unlike #toUrlSafe(String), the caller need no

(final String url)

Source from the content-addressed store, hash-verified

228 * @throws MalformedURLException if the URL string cannot be converted to a URL instance
229 */
230 public static URL toUrlUnsafe(final String url) throws MalformedURLException {
231 WebAssert.notNull("url", url);
232
233 final String protocol = StringUtils.substringBefore(url, ":").toLowerCase(Locale.ROOT);
234
235 if (protocol.isEmpty() || UrlUtils.isNormalUrlProtocol(protocol)) {
236 final URL response = new URL(url);
237 if (response.getProtocol().startsWith("http")
238 && StringUtils.isEmptyOrNull(response.getHost())) {
239 throw new MalformedURLException("Missing host name in url: " + url);
240 }
241 return response;
242 }
243
244 if (JavaScriptURLConnection.JAVASCRIPT_PREFIX.equals(protocol + ":")) {
245 return new URL(null, url, JS_HANDLER);
246 }
247
248 if (ABOUT.equals(protocol)) {
249 if (ABOUT_BLANK.equalsIgnoreCase(url)) {
250 return URL_ABOUT_BLANK;
251 }
252 return new URL(null, url, ABOUT_HANDLER);
253 }
254
255 if ("data".equals(protocol)) {
256 return new URL(null, url, DATA_HANDLER);
257 }
258
259 return new URL(null, url, AnyHandler.INSTANCE);
260 }
261
262 /**
263 * <p>Encodes illegal characters in the specified URL's path, query string and anchor according to the URL

Callers 7

getPageMethod · 0.95
expandUrlMethod · 0.95
onWebSocketTextMethod · 0.95
onWebSocketBinaryMethod · 0.95
jsConstructorMethod · 0.95
setHrefMethod · 0.95
toUrlSafeMethod · 0.95

Calls 9

notNullMethod · 0.95
substringBeforeMethod · 0.95
isNormalUrlProtocolMethod · 0.95
getProtocolMethod · 0.95
isEmptyOrNullMethod · 0.95
getHostMethod · 0.95
isEmptyMethod · 0.65
startsWithMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected