diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VfsUtilCore.java b/platform/core-api/src/com/intellij/openapi/vfs/VfsUtilCore.java index d594b7d993fb..539e1f27c2e0 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VfsUtilCore.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/VfsUtilCore.java @@ -387,7 +387,7 @@ public class VfsUtilCore { String suffix = url.substring(index + 2); if (SystemInfoRt.isWindows) { - return prefix + "://" + suffix; + return prefix + URLUtil.SCHEME_SEPARATOR + suffix; } else if (removeLocalhostPrefix && prefix.equals(StandardFileSystems.FILE_PROTOCOL) && suffix.startsWith(LOCALHOST_URI_PATH_PREFIX)) { // sometimes (e.g. in Google Chrome for Mac) local file url is prefixed with 'localhost' so we need to remove it diff --git a/platform/platform-impl/src/com/intellij/util/UrlImpl.java b/platform/platform-impl/src/com/intellij/util/UrlImpl.java index ec2d7e02af60..04af1fada4e9 100644 --- a/platform/platform-impl/src/com/intellij/util/UrlImpl.java +++ b/platform/platform-impl/src/com/intellij/util/UrlImpl.java @@ -84,10 +84,17 @@ public final class UrlImpl implements Url { public String toDecodedForm() { StringBuilder builder = new StringBuilder(); if (scheme != null) { - builder.append(scheme).append(URLUtil.SCHEME_SEPARATOR); - } - if (authority != null) { - builder.append(authority); + builder.append(scheme); + if (authority != null || isInLocalFileSystem()) { + builder.append(URLUtil.SCHEME_SEPARATOR); + } + else { + builder.append(':'); + } + + if (authority != null) { + builder.append(authority); + } } builder.append(getPath()); if (parameters != null) { @@ -104,7 +111,8 @@ public final class UrlImpl implements Url { } // relative path - special url, encoding is not required - if (path.charAt(0) != '/' && !isInLocalFileSystem()) { + // authority is null in case of URI or file URL + if ((path.charAt(0) != '/' || authority == null) && !isInLocalFileSystem()) { return toDecodedForm(); } diff --git a/platform/platform-impl/src/com/intellij/util/Urls.java b/platform/platform-impl/src/com/intellij/util/Urls.java index a06247a56456..240c30686ef6 100644 --- a/platform/platform-impl/src/com/intellij/util/Urls.java +++ b/platform/platform-impl/src/com/intellij/util/Urls.java @@ -35,7 +35,7 @@ public final class Urls { private static final Logger LOG = Logger.getInstance(Urls.class); // about ";" see WEB-100359 - private static final Pattern URI_PATTERN = Pattern.compile("^([^:/?#]+)://([^/?#]*)([^?#;]*)(.*)"); + private static final Pattern URI_PATTERN = Pattern.compile("^([^:/?#]+):(//)?([^/?#]*)([^?#;]*)(.*)"); @NotNull public static Url newUri(@NotNull String scheme, @NotNull String path) { @@ -44,7 +44,7 @@ public final class Urls { @NotNull public static Url newFromEncoded(@NotNull String url) { - Url result = parse(url, true); + Url result = parse(url, false); LOG.assertTrue(result != null, url); return result; } @@ -112,19 +112,18 @@ public final class Urls { scheme = "jar:" + scheme; } - String authority = StringUtil.nullize(matcher.group(2)); + String authority = StringUtil.nullize(matcher.group(3)); - String path = StringUtil.nullize(matcher.group(3)); + String path = StringUtil.nullize(matcher.group(4)); if (path != null) { path = FileUtil.toCanonicalUriPath(path); } - String parameters = matcher.group(4); - if (authority != null && StandardFileSystems.FILE_PROTOCOL.equals(scheme)) { + if (authority != null && (StandardFileSystems.FILE_PROTOCOL.equals(scheme) || StringUtil.isEmpty(matcher.group(2)))) { path = path == null ? authority : (authority + path); authority = null; } - return new UrlImpl(scheme, authority, path, parameters); + return new UrlImpl(scheme, authority, path, matcher.group(5)); } // must not be used in NodeJS