You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by lk...@apache.org on 2020/10/12 19:02:33 UTC
[netbeans] branch master updated: [NETBEANS-4895] Improve archive
detection of a non-existent file.
This is an automated email from the ASF dual-hosted git repository.
lkishalmi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 9f82bc3 [NETBEANS-4895] Improve archive detection of a non-existent file.
9f82bc3 is described below
commit 9f82bc38bc3ab23a9627f1a2c3e27822a3e60c45
Author: Laszlo Kishalmi <la...@gmail.com>
AuthorDate: Sat Oct 10 08:06:44 2020 -0700
[NETBEANS-4895] Improve archive detection of a non-existent file.
---
.../src/org/openide/filesystems/JarArchiveRootProvider.java | 12 +++++++++---
.../unit/src/org/openide/filesystems/IsArchiveFileTest.java | 1 +
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/platform/openide.filesystems/src/org/openide/filesystems/JarArchiveRootProvider.java b/platform/openide.filesystems/src/org/openide/filesystems/JarArchiveRootProvider.java
index 0cd14fc..7253397 100644
--- a/platform/openide.filesystems/src/org/openide/filesystems/JarArchiveRootProvider.java
+++ b/platform/openide.filesystems/src/org/openide/filesystems/JarArchiveRootProvider.java
@@ -25,7 +25,9 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import java.util.WeakHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -46,6 +48,8 @@ final class JarArchiveRootProvider implements ArchiveRootProvider {
/** Cache for {@link #isArchiveFile(FileObject)}. */
private static final Map</*@GuardedBy("archiveFileCache")*/FileObject, Boolean> archiveFileCache = Collections.synchronizedMap(new WeakHashMap<FileObject,Boolean>());
+ private static final Set<String> KNOWN_ZIP_EXTENSIONS = new HashSet<>(Arrays.asList("jar", "war", "zip", "ear", "sar", "rar")); //NOI18N
+
@Override
public boolean isArchiveFile(URL url, boolean strict) {
if (PROTOCOL.equals(url.getProtocol())) { //NOI18N
@@ -181,11 +185,13 @@ final class JarArchiveRootProvider implements ArchiveRootProvider {
/**
* Tests if a non existent path represents a file.
* @param path to be tested, separated by '/'.
- * @return true if the file has '.' after last '/'.
+ * @return true if the file has '.' after last '/' and the text after
+ * the '.' is a known zip extension.
*/
private static boolean isArchiveFile (final String path) {
- int index = path.lastIndexOf('.'); //NOI18N
- return (index != -1) && (index > path.lastIndexOf('/') + 1); //NOI18N
+ int dot = path.lastIndexOf('.'); //NOI18N
+ int slash = path.lastIndexOf('/'); //NOI18N
+ return (dot != -1) && (dot > slash + 1) && KNOWN_ZIP_EXTENSIONS.contains(path.substring(dot + 1));
}
}
diff --git a/platform/openide.filesystems/test/unit/src/org/openide/filesystems/IsArchiveFileTest.java b/platform/openide.filesystems/test/unit/src/org/openide/filesystems/IsArchiveFileTest.java
index ccca4a7..412ce5a 100644
--- a/platform/openide.filesystems/test/unit/src/org/openide/filesystems/IsArchiveFileTest.java
+++ b/platform/openide.filesystems/test/unit/src/org/openide/filesystems/IsArchiveFileTest.java
@@ -108,6 +108,7 @@ public class IsArchiveFileTest extends NbTestCase {
assertFalse (FileUtil.isArchiveFile(new URL("jar:file:/foo.jar!/")));
assertFalse (FileUtil.isArchiveFile(new URL("file:/foo/")));
+ assertFalse (FileUtil.isArchiveFile(new URL("file:/javafx.base")));
assertTrue (FileUtil.isArchiveFile(new URL("file:/foo.jar")));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists