Author: ggregory
Date: Fri Jan 25 16:06:31 2019
New Revision: 1852148

URL: http://svn.apache.org/viewvc?rev=1852148&view=rev
Log:
[VFS-637] Zip files with legacy encoding and special characters let VFS crash.
      

Added:
    
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystemConfigBuilder.java
    
commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetNullTestCase.java
    
commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetTestCase.java
Modified:
    
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemOptions.java
    
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java
    
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileProvider.java
    
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java
    
commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/test/SftpProviderTestCase.java
    commons/proper/vfs/trunk/src/changes/changes.xml

Modified: 
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemOptions.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemOptions.java?rev=1852148&r1=1852147&r2=1852148&view=diff
==============================================================================
--- 
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemOptions.java
 (original)
+++ 
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemOptions.java
 Fri Jan 25 16:06:31 2019
@@ -42,6 +42,7 @@ import java.util.TreeMap;
  * @see org.apache.commons.vfs2.provider.ram.RamFileSystemConfigBuilder
  * @see org.apache.commons.vfs2.provider.res.ResourceFileSystemConfigBuilder
  * @see org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder
+ * @see org.apache.commons.vfs2.provider.zip.ZipFileSystemConfigBuilder
  *
  */
 public final class FileSystemOptions implements Cloneable {

Modified: 
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java?rev=1852148&r1=1852147&r2=1852148&view=diff
==============================================================================
--- 
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java
 (original)
+++ 
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java
 Fri Jan 25 16:06:31 2019
@@ -129,14 +129,17 @@ public final class SftpClientFactory {
             final String proxyHost = builder.getProxyHost(fileSystemOptions);
             if (proxyHost != null) {
                 final int proxyPort = builder.getProxyPort(fileSystemOptions);
+                final String proxyUser = 
builder.getProxyUser(fileSystemOptions);
+                final String proxyPassword = 
builder.getProxyPassword(fileSystemOptions);
                 final SftpFileSystemConfigBuilder.ProxyType proxyType = 
builder.getProxyType(fileSystemOptions);
                 Proxy proxy = null;
                 if (SftpFileSystemConfigBuilder.PROXY_HTTP.equals(proxyType)) {
-                    proxy = createProxyHTTP(proxyHost, proxyPort);
+                    proxy = createProxyHTTP(proxyHost, proxyPort, proxyUser, 
proxyPassword);
                 } else if 
(SftpFileSystemConfigBuilder.PROXY_SOCKS5.equals(proxyType)) {
-                    proxy = createProxySOCKS5(proxyHost, proxyPort);
+                    proxy = createProxySOCKS5(proxyHost, proxyPort, proxyUser, 
proxyPassword);
                 } else if 
(SftpFileSystemConfigBuilder.PROXY_STREAM.equals(proxyType)) {
-                    proxy = createStreamProxy(proxyHost, proxyPort, 
fileSystemOptions, builder);
+                    proxy = createStreamProxy(proxyHost, proxyPort, proxyUser,
+                            proxyPassword, fileSystemOptions, builder);
                 }
 
                 if (proxy != null) {
@@ -215,16 +218,16 @@ public final class SftpClientFactory {
     }
 
     private static Proxy createStreamProxy(final String proxyHost, final int 
proxyPort,
-            final FileSystemOptions fileSystemOptions, final 
SftpFileSystemConfigBuilder builder) {
+                                           final String proxyUser, final 
String proxyPassword,
+                                           final FileSystemOptions 
fileSystemOptions,
+                                           final SftpFileSystemConfigBuilder 
builder) {
         Proxy proxy;
         // Use a stream proxy, i.e. it will use a remote host as a proxy
         // and run a command (e.g. netcat) that forwards input/output
         // to the target host.
 
         // Here we get the settings for connecting to the proxy:
-        // user, password, options and a command
-        final String proxyUser = builder.getProxyUser(fileSystemOptions);
-        final String proxyPassword = 
builder.getProxyPassword(fileSystemOptions);
+        // options and a command
         final FileSystemOptions proxyOptions = 
builder.getProxyOptions(fileSystemOptions);
 
         final String proxyCommand = builder.getProxyCommand(fileSystemOptions);
@@ -234,12 +237,22 @@ public final class SftpClientFactory {
         return proxy;
     }
 
-    private static ProxySOCKS5 createProxySOCKS5(final String proxyHost, final 
int proxyPort) {
-        return proxyPort == 0 ? new ProxySOCKS5(proxyHost) : new 
ProxySOCKS5(proxyHost, proxyPort);
+    private static ProxySOCKS5 createProxySOCKS5(final String proxyHost, final 
int proxyPort,
+                                                 final String proxyUser, final 
String proxyPassword) {
+        ProxySOCKS5 proxySOCKS5 = proxyPort == 0 ? new ProxySOCKS5(proxyHost) 
: new ProxySOCKS5(proxyHost, proxyPort);
+        if(proxyUser != null && proxyPassword != null) {
+            proxySOCKS5.setUserPasswd(proxyUser, proxyPassword);
+        }
+        return proxySOCKS5;
     }
 
-    private static ProxyHTTP createProxyHTTP(final String proxyHost, final int 
proxyPort) {
-        return proxyPort == 0 ? new ProxyHTTP(proxyHost) : new 
ProxyHTTP(proxyHost, proxyPort);
+    private static ProxyHTTP createProxyHTTP(final String proxyHost, final int 
proxyPort,
+                                             final String proxyUser, final 
String proxyPassword) {
+        ProxyHTTP proxyHTTP = proxyPort == 0 ? new ProxyHTTP(proxyHost) : new 
ProxyHTTP(proxyHost, proxyPort);
+        if(proxyUser != null && proxyPassword != null) {
+            proxyHTTP.setUserPasswd(proxyUser, proxyPassword);
+        }
+        return proxyHTTP;
     }
 
     /**

Modified: 
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileProvider.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileProvider.java?rev=1852148&r1=1852147&r2=1852148&view=diff
==============================================================================
--- 
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileProvider.java
 (original)
+++ 
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileProvider.java
 Fri Jan 25 16:06:31 2019
@@ -24,12 +24,14 @@ import org.apache.commons.vfs2.Capabilit
 import org.apache.commons.vfs2.FileName;
 import org.apache.commons.vfs2.FileObject;
 import org.apache.commons.vfs2.FileSystem;
+import org.apache.commons.vfs2.FileSystemConfigBuilder;
 import org.apache.commons.vfs2.FileSystemException;
 import org.apache.commons.vfs2.FileSystemOptions;
 import org.apache.commons.vfs2.FileType;
 import org.apache.commons.vfs2.provider.AbstractFileName;
 import org.apache.commons.vfs2.provider.AbstractLayeredFileProvider;
 import org.apache.commons.vfs2.provider.LayeredFileName;
+import org.apache.commons.vfs2.provider.hdfs.HdfsFileSystemConfigBuilder;
 
 /**
  * A file system provider for ZIP files. Provides read-only file systems.
@@ -45,10 +47,11 @@ public class ZipFileProvider extends Abs
     }
 
     /**
-     * Creates a layered file system. This method is called if the file system 
is not cached.
+     * Creates a layered file system. This method is called if the file system 
is
+     * not cached.
      *
      * @param scheme The URI scheme.
-     * @param file The file to create the file system on top of.
+     * @param file   The file to create the file system on top of.
      * @return The file system.
      */
     @Override
@@ -63,4 +66,15 @@ public class ZipFileProvider extends Abs
     public Collection<Capability> getCapabilities() {
         return capabilities;
     }
+
+    /**
+     * Return config builder.
+     *
+     * @return A config builder for ZipFileProvider.
+     * @see 
org.apache.commons.vfs2.provider.AbstractFileProvider#getConfigBuilder()
+     */
+    @Override
+    public FileSystemConfigBuilder getConfigBuilder() {
+        return ZipFileSystemConfigBuilder.getInstance();
+    }
 }

Modified: 
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java?rev=1852148&r1=1852147&r2=1852148&view=diff
==============================================================================
--- 
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java
 (original)
+++ 
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java
 Fri Jan 25 16:06:31 2019
@@ -18,6 +18,7 @@ package org.apache.commons.vfs2.provider
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Enumeration;
@@ -47,6 +48,7 @@ public class ZipFileSystem extends Abstr
     private static final Log LOG = LogFactory.getLog(ZipFileSystem.class);
 
     private final File file;
+    private final Charset charset;
     private ZipFile zipFile;
 
     /**
@@ -57,18 +59,17 @@ public class ZipFileSystem extends Abstr
     public ZipFileSystem(final AbstractFileName rootName, final FileObject 
parentLayer,
             final FileSystemOptions fileSystemOptions) throws 
FileSystemException {
         super(rootName, parentLayer, fileSystemOptions);
-
+        
         // Make a local copy of the file
         file = parentLayer.getFileSystem().replicateFile(parentLayer, 
Selectors.SELECT_SELF);
-
+        this.charset = 
ZipFileSystemConfigBuilder.getInstance().getCharset(fileSystemOptions);
+        
         // Open the Zip file
         if (!file.exists()) {
             // Don't need to do anything
             zipFile = null;
             return;
         }
-
-        // zipFile = createZipFile(this.file);
     }
 
     @Override
@@ -136,7 +137,7 @@ public class ZipFileSystem extends Abstr
 
     protected ZipFile createZipFile(final File file) throws 
FileSystemException {
         try {
-            return new ZipFile(file);
+            return charset == null ? new ZipFile(file) : new ZipFile(file, 
charset);
         } catch (final IOException ioe) {
             throw new 
FileSystemException("vfs.provider.zip/open-zip-file.error", file, ioe);
         }
@@ -181,6 +182,10 @@ public class ZipFileSystem extends Abstr
         cache.put(file.getName(), file);
     }
 
+    protected Charset getCharset() {
+        return charset;
+    }
+
     /**
      * Returns a cached file.
      */

Added: 
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystemConfigBuilder.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystemConfigBuilder.java?rev=1852148&view=auto
==============================================================================
--- 
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystemConfigBuilder.java
 (added)
+++ 
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystemConfigBuilder.java
 Fri Jan 25 16:06:31 2019
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.vfs2.provider.zip;
+
+import java.nio.charset.Charset;
+
+import org.apache.commons.vfs2.FileSystem;
+import org.apache.commons.vfs2.FileSystemConfigBuilder;
+import org.apache.commons.vfs2.FileSystemOptions;
+
+public class ZipFileSystemConfigBuilder extends FileSystemConfigBuilder {
+
+    private static final String _PREFIX = 
ZipFileSystemConfigBuilder.class.getName();
+    private static final ZipFileSystemConfigBuilder INSTANCE = new 
ZipFileSystemConfigBuilder();
+    private static final String KEY_CHARSET = _PREFIX + ".charset";
+    
+    public static final ZipFileSystemConfigBuilder getInstance() {
+        return INSTANCE;
+    }
+    
+    private ZipFileSystemConfigBuilder() {
+        super("zip.");
+    }
+    
+    public Charset getCharset(final FileSystemOptions opts) {
+        return (Charset) getParam(opts, KEY_CHARSET);
+    }
+    
+    @Override
+    protected Class<? extends FileSystem> getConfigClass() {
+        return ZipFileSystem.class;
+    }
+
+    public void setCharset(final FileSystemOptions opts, final Charset 
charset) {
+        setParam(opts, KEY_CHARSET, charset);
+    }
+
+}

Modified: 
commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/test/SftpProviderTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/test/SftpProviderTestCase.java?rev=1852148&r1=1852147&r2=1852148&view=diff
==============================================================================
--- 
commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/test/SftpProviderTestCase.java
 (original)
+++ 
commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/test/SftpProviderTestCase.java
 Fri Jan 25 16:06:31 2019
@@ -80,6 +80,11 @@ import org.apache.sshd.server.sftp.SftpS
 import com.jcraft.jsch.SftpATTRS;
 import com.jcraft.jsch.TestIdentityRepositoryFactory;
 
+import static 
org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder.ProxyType;
+import static 
org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder.PROXY_HTTP;
+import static 
org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder.PROXY_SOCKS5;
+import static 
org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder.PROXY_STREAM;
+
 /**
  * Tests cases for the SFTP provider.
  * <p>
@@ -173,8 +178,8 @@ public class SftpProviderTestCase extend
 
     private static final String TEST_URI = "test.sftp.uri";
 
-    /** True if we are testing the SFTP stream proxy */
-    private final boolean streamProxyMode;
+    /** Denotes which type of proxy (if any) we are using */
+    private final ProxyType proxyType;
 
     private static String getSystemTestUriOverride() {
         return System.getProperty(TEST_URI);
@@ -299,7 +304,7 @@ public class SftpProviderTestCase extend
         final TestSuite suite = new TestSuite();
 
         // --- Standard VFS test suite
-        final SftpProviderTestCase standardTestCase = new 
SftpProviderTestCase(false);
+        final SftpProviderTestCase standardTestCase = new 
SftpProviderTestCase(null);
         final ProviderTestSuite sftpSuite = new 
BaseProviderTestSuite(standardTestCase);
 
         // VFS-405: set/get permissions
@@ -311,7 +316,9 @@ public class SftpProviderTestCase extend
         // We override the addBaseTests method so that only
         // one test is run (we just test that the input/output are correctly 
forwarded, and
         // hence if the reading test succeeds/fails the other will also 
succeed/fail)
-        final SftpProviderTestCase streamProxyTestCase = new 
SftpProviderTestCase(true);
+        // --- VFS-663: HTTP / SOCKS5 proxy test suite
+        // Following the example set by VFS-440
+        final SftpProviderTestCase streamProxyTestCase = new 
SftpProviderTestCase(PROXY_STREAM);
         final ProviderTestSuite sftpStreamSuite = new 
BaseProviderTestSuite(streamProxyTestCase) {
             @Override
             protected void addBaseTests() throws Exception {
@@ -321,6 +328,28 @@ public class SftpProviderTestCase extend
         };
         suite.addTest(sftpStreamSuite);
 
+        // --- VFS-663: HTTP / SOCKS5 proxy test suite
+        // Following the example set by VFS-440
+        final SftpProviderTestCase httpProxyTestCase = new 
SftpProviderTestCase(PROXY_HTTP);
+        final ProviderTestSuite sftpHttpSuite = new 
BaseProviderTestSuite(httpProxyTestCase) {
+            @Override
+            protected void addBaseTests() throws Exception {
+                // Just tries to read
+                addTests(ProviderReadTests.class);
+            }
+        };
+        suite.addTest(sftpHttpSuite);
+
+        final SftpProviderTestCase socks5ProxyTestCase = new 
SftpProviderTestCase(PROXY_SOCKS5);
+        final ProviderTestSuite sftpSocks5Suite = new 
BaseProviderTestSuite(socks5ProxyTestCase) {
+            @Override
+            protected void addBaseTests() throws Exception {
+                // Just tries to read
+                addTests(ProviderReadTests.class);
+            }
+        };
+        suite.addTest(sftpSocks5Suite);
+
         // Decorate the test suite to set up the Sftp server
         final TestSetup setup = new TestSetup(suite) {
             @Override
@@ -353,8 +382,8 @@ public class SftpProviderTestCase extend
         }
     }
 
-    public SftpProviderTestCase(final boolean streamProxyMode) {
-        this.streamProxyMode = streamProxyMode;
+    public SftpProviderTestCase(final SftpFileSystemConfigBuilder.ProxyType 
proxyType) {
+        this.proxyType = proxyType;
     }
 
     /**
@@ -373,7 +402,7 @@ public class SftpProviderTestCase extend
         builder.setUserInfo(fileSystemOptions, new TrustEveryoneUserInfo());
         builder.setIdentityRepositoryFactory(fileSystemOptions, new 
TestIdentityRepositoryFactory());
 
-        if (streamProxyMode) {
+        if (proxyType == PROXY_STREAM) {
             final FileSystemOptions proxyOptions = (FileSystemOptions) 
fileSystemOptions.clone();
 
             final URI parsedURI = new URI(uri);
@@ -392,6 +421,42 @@ public class SftpProviderTestCase extend
             builder.setProxyPassword(fileSystemOptions, 
parsedURI.getAuthority());
 
             // Set up the new URI
+            uri = String.format("sftp://%s@localhost:%d";, userInfo, 
parsedURI.getPort());
+        }
+
+        if (proxyType == PROXY_HTTP) {
+            final URI parsedURI = new URI(uri);
+            final String userInfo = parsedURI.getUserInfo();
+            final String[] userFields = userInfo.split(":", 2);
+
+            builder.setProxyType(fileSystemOptions, PROXY_HTTP);
+            builder.setProxyUser(fileSystemOptions, userFields[0]);
+            if (userFields.length > 1) {
+                builder.setProxyPassword(fileSystemOptions, userFields[1]);
+            }
+            builder.setProxyHost(fileSystemOptions, parsedURI.getHost());
+            builder.setProxyPort(fileSystemOptions, parsedURI.getPort());
+            builder.setProxyPassword(fileSystemOptions, 
parsedURI.getAuthority());
+
+            // Set up the new URI
+            uri = String.format("sftp://%s@localhost:%d";, userInfo, 
parsedURI.getPort());
+        }
+
+        if (proxyType == PROXY_SOCKS5) {
+            final URI parsedURI = new URI(uri);
+            final String userInfo = parsedURI.getUserInfo();
+            final String[] userFields = userInfo.split(":", 2);
+
+            builder.setProxyType(fileSystemOptions, PROXY_SOCKS5);
+            builder.setProxyUser(fileSystemOptions, userFields[0]);
+            if (userFields.length > 1) {
+                builder.setProxyPassword(fileSystemOptions, userFields[1]);
+            }
+            builder.setProxyHost(fileSystemOptions, parsedURI.getHost());
+            builder.setProxyPort(fileSystemOptions, parsedURI.getPort());
+            builder.setProxyPassword(fileSystemOptions, 
parsedURI.getAuthority());
+
+            // Set up the new URI
             uri = String.format("sftp://%s@localhost:%d";, userInfo, 
parsedURI.getPort());
         }
 

Added: 
commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetNullTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetNullTestCase.java?rev=1852148&view=auto
==============================================================================
--- 
commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetNullTestCase.java
 (added)
+++ 
commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetNullTestCase.java
 Fri Jan 25 16:06:31 2019
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs2.provider.zip;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+
+import org.apache.commons.AbstractVfsTestCase;
+import org.apache.commons.vfs2.FileObject;
+import org.apache.commons.vfs2.FileSystem;
+import org.apache.commons.vfs2.FileSystemManager;
+import org.apache.commons.vfs2.FileSystemOptions;
+import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
+import org.apache.commons.vfs2.provider.zip.ZipFileProvider;
+import org.apache.commons.vfs2.provider.zip.ZipFileSystem;
+import org.apache.commons.vfs2.provider.zip.ZipFileSystemConfigBuilder;
+import org.apache.commons.vfs2.test.AbstractProviderTestConfig;
+import org.apache.commons.vfs2.test.ProviderTestSuite;
+import org.junit.Assert;
+
+import junit.framework.Test;
+
+/**
+ * Tests for the Zip file system.
+ */
+public class ZipProviderWithCharsetNullTestCase extends 
AbstractProviderTestConfig {
+    /**
+     * Creates the test suite for the zip file system.
+     */
+    public static Test suite() throws Exception {
+        return new ProviderTestSuite(new ZipProviderWithCharsetNullTestCase(), 
true);
+    }
+
+    /**
+     * Prepares the file system manager.
+     */
+    @Override
+    public void prepare(final DefaultFileSystemManager manager) throws 
Exception {
+        manager.addProvider("zip", new ZipFileProvider());
+        manager.addExtensionMap("zip", "zip");
+        manager.addMimeTypeMap("application/zip", "zip");
+    }
+
+    /**
+     * Returns the base folder for read tests.
+     */
+    @Override
+    public FileObject getBaseTestFolder(final FileSystemManager manager) 
throws Exception {
+        final FileSystemOptions opts = new FileSystemOptions();
+        final ZipFileSystemConfigBuilder builder = 
ZipFileSystemConfigBuilder.getInstance();
+        // Tests null as the default.
+        builder.setCharset(opts, null);
+
+        final File zipFile = AbstractVfsTestCase.getTestResource("test.zip");
+        final String uri = "zip:file:" + zipFile.getAbsolutePath() + "!/";
+        FileObject resolvedFile = manager.resolveFile(uri, opts);
+        FileSystem fileSystem = resolvedFile.getFileSystem();
+        Assert.assertTrue(fileSystem instanceof ZipFileSystem);
+        ZipFileSystem zipFileSystem = (ZipFileSystem) fileSystem;
+        Assert.assertEquals(null, zipFileSystem.getCharset());
+        return resolvedFile;
+    }
+}

Added: 
commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetTestCase.java?rev=1852148&view=auto
==============================================================================
--- 
commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetTestCase.java
 (added)
+++ 
commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetTestCase.java
 Fri Jan 25 16:06:31 2019
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs2.provider.zip;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+
+import org.apache.commons.AbstractVfsTestCase;
+import org.apache.commons.vfs2.FileObject;
+import org.apache.commons.vfs2.FileSystem;
+import org.apache.commons.vfs2.FileSystemManager;
+import org.apache.commons.vfs2.FileSystemOptions;
+import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
+import org.apache.commons.vfs2.provider.zip.ZipFileProvider;
+import org.apache.commons.vfs2.provider.zip.ZipFileSystem;
+import org.apache.commons.vfs2.provider.zip.ZipFileSystemConfigBuilder;
+import org.apache.commons.vfs2.test.AbstractProviderTestConfig;
+import org.apache.commons.vfs2.test.ProviderTestSuite;
+import org.junit.Assert;
+
+import junit.framework.Test;
+
+/**
+ * Tests for the Zip file system.
+ */
+public class ZipProviderWithCharsetTestCase extends AbstractProviderTestConfig 
{
+    /**
+     * Creates the test suite for the zip file system.
+     */
+    public static Test suite() throws Exception {
+        return new ProviderTestSuite(new ZipProviderWithCharsetTestCase(), 
true);
+    }
+
+    /**
+     * Prepares the file system manager.
+     */
+    @Override
+    public void prepare(final DefaultFileSystemManager manager) throws 
Exception {
+        manager.addProvider("zip", new ZipFileProvider());
+        manager.addExtensionMap("zip", "zip");
+        manager.addMimeTypeMap("application/zip", "zip");
+    }
+
+    /**
+     * Returns the base folder for read tests.
+     */
+    @Override
+    public FileObject getBaseTestFolder(final FileSystemManager manager) 
throws Exception {
+        final FileSystemOptions opts = new FileSystemOptions();
+        final ZipFileSystemConfigBuilder builder = 
ZipFileSystemConfigBuilder.getInstance();
+        // Tests the same charset as the default but we exercise having a 
Charset set.
+        builder.setCharset(opts, StandardCharsets.UTF_8);
+
+        final File zipFile = AbstractVfsTestCase.getTestResource("test.zip");
+        final String uri = "zip:file:" + zipFile.getAbsolutePath() + "!/";
+        FileObject resolvedFile = manager.resolveFile(uri, opts);
+        FileSystem fileSystem = resolvedFile.getFileSystem();
+        Assert.assertTrue(fileSystem instanceof ZipFileSystem);
+        ZipFileSystem zipFileSystem = (ZipFileSystem) fileSystem;
+        Assert.assertEquals(StandardCharsets.UTF_8, 
zipFileSystem.getCharset());
+        return resolvedFile;
+    }
+}

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1852148&r1=1852147&r2=1852148&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Fri Jan 25 16:06:31 2019
@@ -131,6 +131,9 @@ The <action> type attribute can be add,u
       <action issue="VFS-673" dev="ggregory" type="add" due-to="Daniel Banks">
         DefaultFileSystemManager should implement AutoCloseable.
       </action>
+      <action issue="VFS-637" dev="ggregory" type="add" due-to="Gary Gregory">
+        Zip files with legacy encoding and special characters let VFS crash.
+      </action>
     </release>
     <release version="2.2" date="2017-10-06" description="New features and bug 
fix release.">
       <action issue="VFS-642" dev="pschumacher" type="update" 
due-to="ilangoldfeld">


Reply via email to