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)
| 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 |
no test coverage detected