From 1ee1bf11658a70a29d298fc284efa4dddd4bbce3 Mon Sep 17 00:00:00 2001 From: lgemeinhardt Date: Wed, 23 Jan 2019 17:34:33 -0800 Subject: [PATCH] Fix zip file entry resolution on Windows. See also https://github.com/google/j2cl/issues/9. Fixes https://github.com/google/closure-compiler/pull/3206. Closes https://github.com/google/closure-compiler/pull/3207. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=230635801 --- src/com/google/javascript/jscomp/SourceFile.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/com/google/javascript/jscomp/SourceFile.java b/src/com/google/javascript/jscomp/SourceFile.java index 6fc349ce34c..e740cb6af5a 100644 --- a/src/com/google/javascript/jscomp/SourceFile.java +++ b/src/com/google/javascript/jscomp/SourceFile.java @@ -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; @@ -358,13 +359,14 @@ public static List 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]; @@ -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()