From 3dd6b59650fa470621deae27780dab19cbb446d2 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 17 Apr 2015 01:04:56 +0000 Subject: [PATCH] LUCENE-6430: fix URI delegation for non-ascii files git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1674177 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/mockfile/TestMockFilesystems.java | 16 ++++++++++++++++ .../mockfile/FilterFileSystemProvider.java | 12 +----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lucene/core/src/test/org/apache/lucene/mockfile/TestMockFilesystems.java b/lucene/core/src/test/org/apache/lucene/mockfile/TestMockFilesystems.java index 04800015eb7..507ce6fa1aa 100644 --- a/lucene/core/src/test/org/apache/lucene/mockfile/TestMockFilesystems.java +++ b/lucene/core/src/test/org/apache/lucene/mockfile/TestMockFilesystems.java @@ -357,4 +357,20 @@ public class TestMockFilesystems extends LuceneTestCase { assertEquals(f1.hashCode(), f1Again.hashCode()); assertFalse(f1.equals(f2)); } + + public void testURI() throws IOException { + Path dir = FilterPath.unwrap(createTempDir()); + FileSystem fs = new FilterFileSystemProvider("test://", dir.getFileSystem()).getFileSystem(URI.create("file:///")); + Path wrapped = new FilterPath(dir, fs); + + Path f1 = wrapped.resolve("file1"); + URI uri = f1.toUri(); + Path f2 = fs.provider().getPath(uri); + assertEquals(f1, f2); + + Path f3 = wrapped.resolve("中国"); + URI uri2 = f3.toUri(); + Path f4 = fs.provider().getPath(uri2); + assertEquals(f3, f4); + } } diff --git a/lucene/test-framework/src/java/org/apache/lucene/mockfile/FilterFileSystemProvider.java b/lucene/test-framework/src/java/org/apache/lucene/mockfile/FilterFileSystemProvider.java index 0679c842ffd..1fe6dacbaf9 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/mockfile/FilterFileSystemProvider.java +++ b/lucene/test-framework/src/java/org/apache/lucene/mockfile/FilterFileSystemProvider.java @@ -17,12 +17,10 @@ package org.apache.lucene.mockfile; * limitations under the License. */ -import java.io.IOError; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URI; -import java.net.URISyntaxException; import java.nio.channels.AsynchronousFileChannel; import java.nio.channels.FileChannel; import java.nio.channels.SeekableByteChannel; @@ -126,7 +124,7 @@ public class FilterFileSystemProvider extends FileSystemProvider { if (fileSystem == null) { throw new IllegalStateException("subclass did not initialize singleton filesystem"); } - Path path = delegate.getPath(toDelegate(uri)); + Path path = delegate.getPath(uri); return new FilterPath(path, fileSystem); } @@ -258,14 +256,6 @@ public class FilterFileSystemProvider extends FileSystemProvider { } } - private URI toDelegate(URI uri) { - try { - return new URI(delegate.getScheme(), uri.getSchemeSpecificPart(), uri.getFragment()); - } catch (URISyntaxException e) { - throw new IOError(e); - } - } - /** * Override to trigger some behavior when the filesystem is closed. *