Skip to content

Commit

Permalink
Fix zip file entry resolution on Windows.
Browse files Browse the repository at this point in the history
See also google/j2cl#9.

Fixes #3206.
Closes #3207.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=230635801
  • Loading branch information
lgemeinhardt authored and tjgq committed Jan 25, 2019
1 parent df7cb68 commit 4ac9af9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/com/google/javascript/jscomp/SourceFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

Expand Down Expand Up @@ -358,13 +359,14 @@ public static List<SourceFile> fromZipFile(String zipName, Charset inputCharset)
private static final String JAR_URL_PREFIX = "jar:file:";

private static boolean isZipEntry(String path) {
return path.contains(".zip!/") && (path.endsWith(".js") || path.endsWith(".js.map"));
return path.contains(".zip!" + File.separator)
&& (path.endsWith(".js") || path.endsWith(".js.map"));
}

@GwtIncompatible("java.io.File")
private static SourceFile fromZipEntry(String zipURL, Charset inputCharset) {
checkArgument(isZipEntry(zipURL));
String[] components = zipURL.split(BANG_SLASH);
String[] components = zipURL.split(Pattern.quote(BANG_SLASH.replace("/", File.separator)));
try {
String zipPath = components[0];
String relativePath = components[1];
Expand All @@ -378,7 +380,8 @@ private static SourceFile fromZipEntry(String zipURL, Charset inputCharset) {
public static SourceFile fromZipEntry(
String originalZipPath, String absoluteZipPath, String entryPath, Charset inputCharset)
throws MalformedURLException {
String zipEntryPath = JAR_URL_PREFIX + absoluteZipPath + BANG_SLASH + entryPath;
String zipEntryPath =
JAR_URL_PREFIX + absoluteZipPath + BANG_SLASH + entryPath.replace(File.separator, "/");
URL zipEntryUrl = new URL(zipEntryPath);

return builder()
Expand Down

0 comments on commit 4ac9af9

Please sign in to comment.