WEB-703 (firefox is not yet tested, windows is also untested)

This commit is contained in:
Vladimir Krivosheev
2012-12-07 18:42:48 +04:00
parent c60116561d
commit 6df84deb85
3 changed files with 39 additions and 16 deletions
@@ -50,6 +50,8 @@ public class VfsUtil extends VfsUtilCore {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vfs.VfsUtil");
public static final char VFS_PATH_SEPARATOR = '/';
private static final String LOCALHOST_URI_PATH_PREFIX = "localhost/";
public static void saveText(@NotNull VirtualFile file, @NotNull String text) throws IOException {
Charset charset = file.getCharset();
file.setBinaryContent(text.getBytes(charset.name()));
@@ -464,16 +466,32 @@ public class VfsUtil extends VfsUtilCore {
}
@NotNull
public static String fixURLforIDEA(@NotNull String url ) {
public static String fixURLforIDEA(@NotNull String url) {
// removeLocalhostPrefix - false due to backward compatibility reasons
return toIdeaUrl(url, false);
}
@NotNull
public static String toIdeaUrl(@NotNull String url) {
return toIdeaUrl(url, true);
}
@NotNull
public static String toIdeaUrl(@NotNull String url, boolean removeLocalhostPrefix) {
int idx = url.indexOf(":/");
if( idx >= 0 && idx+2 < url.length() && url.charAt(idx+2) != '/' ) {
if (idx >= 0 && idx + 2 < url.length() && url.charAt(idx + 2) != '/') {
String prefix = url.substring(0, idx);
String suffix = url.substring(idx+2);
String suffix = url.substring(idx + 2);
if (SystemInfo.isWindows) {
url = prefix+"://"+suffix;
} else {
url = prefix+":///"+suffix;
return prefix + "://" + 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
return prefix + ":///" + suffix.substring(LOCALHOST_URI_PATH_PREFIX.length());
}
else {
return prefix + ":///" + suffix;
}
}
return url;
@@ -16,14 +16,14 @@
package com.intellij.util.io;
import com.google.common.base.Charsets;
import com.intellij.openapi.util.io.FileUtil;
import gnu.trove.TIntArrayList;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.io.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -103,7 +103,7 @@ public class URLUtil {
while (i < len) {
char c = s.charAt(i);
if (c == '%') {
List<Integer> bytes = new ArrayList<Integer>();
TIntArrayList bytes = new TIntArrayList();
while (i + 2 < len && s.charAt(i) == '%') {
final int d1 = decode(s.charAt(i + 1));
final int d2 = decode(s.charAt(i + 2));
@@ -118,14 +118,10 @@ public class URLUtil {
if (!bytes.isEmpty()) {
final byte[] bytesArray = new byte[bytes.size()];
for (int j = 0; j < bytes.size(); j++) {
bytesArray[j] = (byte)bytes.get(j).intValue();
}
try {
decoded.append(new String(bytesArray, "UTF-8"));
continue;
}
catch (UnsupportedEncodingException ignored) {
bytesArray[j] = (byte)bytes.getQuick(j);
}
decoded.append(new String(bytesArray, Charsets.UTF_8));
continue;
}
}
+9
View File
@@ -20,6 +20,15 @@
<orderEntry type="library" name="OroMatcher" level="project" />
<orderEntry type="library" scope="TEST" name="JUnit4" level="project" />
<orderEntry type="library" scope="TEST" name="Groovy" level="project" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../plugins/gradle/lib/guava-11.0.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
<component name="copyright">
<Base>