diff options
author | Sven Gothel <[email protected]> | 2014-01-22 20:14:00 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-01-22 20:14:00 +0100 |
commit | efb7c478fda04336292104b10c3adf985d59b173 (patch) | |
tree | e8afb47b4067b114f8604eb527839ef5f092d560 /src | |
parent | d0acda31e866040d8dbf8e72f983b78bafcb243a (diff) |
Bug 945 - GlueGen's IOUtil does not consider file URI's authority when converting to file-path or URI (Windows UNC / share host)
Note: Authority for 'file-scheme' URI's is used on Windows to denote the host of the shared resource -> UNC
Following methods of IOUtil didn't consider the authority for file-scheme URI:
'URL toURL(final URI uri)'
'String decodeURIToFilePath(final String uriPath)'
'String decodeURIIfFilePath(final URI uri)'
Further more, the patterns 'patternSingleFS' and 'patternSingleBS'
converted multiple '\' '/' to one replacement.
However, we should not change the separator count and replace them one-by-one.
TestIOUtilURIHandling:
- Added shared-file-host 'filehost' test cases to file URIs and plain file path tests.
- Passed on Unix and Windows.
Added 'make/scripts/test-win32-smb_share.bat'
- Testing actual windows share usage
- Passed on Windows
Diffstat (limited to 'src')
-rw-r--r-- | src/java/com/jogamp/common/util/IOUtil.java | 43 | ||||
-rw-r--r-- | src/junit/com/jogamp/common/util/TestIOUtilURIHandling.java | 39 |
2 files changed, 58 insertions, 24 deletions
diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java index 2bcb58c..60a0ee0 100644 --- a/src/java/com/jogamp/common/util/IOUtil.java +++ b/src/java/com/jogamp/common/util/IOUtil.java @@ -517,6 +517,9 @@ public class IOUtil { * </ul> * </p> * <p> + * Note that a given {@link URI#getAuthority() authority} for <i>file scheme</i>s is preserved to support window's shares. + * </p> + * <p> * Tested w/ unit test <code>com.jogamp.common.util.TestIOUtilURIHandling</code> * </p> * @param uri @@ -531,6 +534,12 @@ public class IOUtil { final boolean isJar = IOUtil.JAR_SCHEME.equals(uriSchema); final URI specificURI = isJar ? JarUtil.getJarSubURI(uri) : uri; final boolean hasJarSubURI = specificURI != uri; + final String authorityS; + { + final String authority = specificURI.getAuthority(); + authorityS = ( null == authority ) ? "" : "//"+authority; + } + if( DEBUG ) { System.err.println("IOUtil.toURL.0: isJAR "+isJar+", hasSubURI "+hasJarSubURI+PlatformPropsImpl.NEWLINE+ "\t, uri "+uri+PlatformPropsImpl.NEWLINE+ @@ -538,6 +547,7 @@ public class IOUtil { "\t ascii -> "+specificURI.toASCIIString()+PlatformPropsImpl.NEWLINE+ "\t ssp -> "+specificURI.getSchemeSpecificPart()+PlatformPropsImpl.NEWLINE+ "\t frag -> "+specificURI.getFragment()+PlatformPropsImpl.NEWLINE+ + "\t auth -> "+authorityS+PlatformPropsImpl.NEWLINE+ /* "//user-info@host:port" */ "\t path -> "+specificURI.getPath()+PlatformPropsImpl.NEWLINE+ "\t path.decoded -> "+decodeFromURI( specificURI.getPath() ) ); } @@ -580,9 +590,9 @@ public class IOUtil { } } if( !hasJarSubURI ) { - urlS = IOUtil.FILE_SCHEME+IOUtil.SCHEME_SEPARATOR+fPathUriS; + urlS = IOUtil.FILE_SCHEME+IOUtil.SCHEME_SEPARATOR+authorityS+fPathUriS; if( DEBUG ) { - System.err.println("IOUtil.toURL.1: fPath "+fPath+PlatformPropsImpl.NEWLINE+ + System.err.println("IOUtil.toURL.1: authorityS "+authorityS+", fPath "+fPath+PlatformPropsImpl.NEWLINE+ "\t -> "+fPathUriS+PlatformPropsImpl.NEWLINE+ "\t -> "+urlS); } @@ -591,9 +601,9 @@ public class IOUtil { } else { final String jarEntry = JarUtil.getJarEntry(uri); final String post = isJar ? IOUtil.JAR_SCHEME_SEPARATOR + jarEntry : ""; - urlS = uriSchema+IOUtil.SCHEME_SEPARATOR+IOUtil.FILE_SCHEME+IOUtil.SCHEME_SEPARATOR+fPathUriS+post; + urlS = uriSchema+IOUtil.SCHEME_SEPARATOR+IOUtil.FILE_SCHEME+IOUtil.SCHEME_SEPARATOR+authorityS+fPathUriS+post; if( DEBUG ) { - System.err.println("IOUtil.toURL.2: fPath "+fPath+PlatformPropsImpl.NEWLINE+ + System.err.println("IOUtil.toURL.2: authorityS "+authorityS+", fPath "+fPath+PlatformPropsImpl.NEWLINE+ "\t -> "+fPathUriS+PlatformPropsImpl.NEWLINE+ "\t, jarEntry "+jarEntry+PlatformPropsImpl.NEWLINE+ "\t, post "+post+PlatformPropsImpl.NEWLINE+ @@ -916,8 +926,8 @@ public class IOUtil { return patternSpaceEnc.matcher(s).replaceAll(" "); } - private static final Pattern patternSingleBS = Pattern.compile("\\\\{1,}"); - private static final Pattern patternSingleFS = Pattern.compile("/{1,}"); + private static final Pattern patternSingleBS = Pattern.compile("\\\\{1}"); + private static final Pattern patternSingleFS = Pattern.compile("/{1}"); /** * Encodes file path characters not complying w/ RFC 2396 and the {@link URI#URI(String)} ctor. @@ -961,8 +971,8 @@ public class IOUtil { * Then it processes the <code>path</code> if {@link File#separatorChar} <code> != '/'</code> * as follows: * <ul> - * <li>drop a starting slash</li> * <li>slash -> backslash</li> + * <li>drop a starting single backslash</li> * </ul> * </p> * @see #decodeFromURI(String) @@ -971,7 +981,7 @@ public class IOUtil { final String path = IOUtil.decodeFromURI(uriPath); if( !File.separator.equals("/") ) { final String r = patternSingleFS.matcher(path).replaceAll("\\\\"); - if( r.startsWith("\\") ) { + if( r.startsWith("\\") && !r.startsWith("\\\\") ) { // '\\\\' denotes UNC hostname, which shall not be cut-off return r.substring(1); } else { return r; @@ -982,15 +992,26 @@ public class IOUtil { /** * If <code>uri</code> is a <i>file scheme</i>, - * implementation returns the decoded {@link URI#getPath()} via {@link #decodeURIToFilePath(String)}, - * otherwise it returns the {@link URI#toASCIIString()} encoded URI. + * implementation returns the decoded <i>[ "//"+{@link URI#getAuthority()} ] + {@link URI#getPath()}</i> via {@link #decodeURIToFilePath(String)}. + * <p> + * Otherwise it returns the {@link URI#toASCIIString()} encoded URI. + * </p> * * @see #decodeFromURI(String) * @see #decodeURIToFilePath(String) */ public static String decodeURIIfFilePath(final URI uri) { if( IOUtil.FILE_SCHEME.equals( uri.getScheme() ) ) { - return decodeURIToFilePath( uri.getPath() ); + final String authorityS; + { + final String authority = uri.getAuthority(); + if( null == authority ) { + authorityS = ""; + } else { + authorityS = "//"+authority; + } + return decodeURIToFilePath(authorityS+uri.getPath()); + } } return uri.toASCIIString(); } diff --git a/src/junit/com/jogamp/common/util/TestIOUtilURIHandling.java b/src/junit/com/jogamp/common/util/TestIOUtilURIHandling.java index ecf950b..efd7030 100644 --- a/src/junit/com/jogamp/common/util/TestIOUtilURIHandling.java +++ b/src/junit/com/jogamp/common/util/TestIOUtilURIHandling.java @@ -84,6 +84,9 @@ public class TestIOUtilURIHandling extends JunitTracer { new String[] {"jar:file:/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class", "jar:file:/gluegen/build-x86_64 öä lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class" }, + new String[] {"jar:file://filehost/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class", + "jar:file://filehost/gluegen/build-x86_64 öä lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class" }, + /** Not possible, '#' is fragment in URI new String[] {"jar:file:/gluegen/%23/gluegen-rt.jar!/", "jar:file:/gluegen/#/gluegen-rt.jar!/" }, */ @@ -111,6 +114,12 @@ public class TestIOUtilURIHandling extends JunitTracer { new String[] {"jar:file:/C:/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class", "jar:file:/C:/gluegen/build-x86_64 öä lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class" }, + new String[] {"jar:file:///C:/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class", + "jar:file:/C:/gluegen/build-x86_64 öä lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class" }, + + new String[] {"jar:file://filehost/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class", + "jar:file://filehost/gluegen/build-x86_64 öä lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class" }, + /** Not possible, '#' is fragment in URI new String[] {"jar:file:/C:/gluegen/%23/gluegen-rt.jar!/", "jar:file:/C:/gluegen/#/gluegen-rt.jar!/" }, */ @@ -160,6 +169,11 @@ public class TestIOUtilURIHandling extends JunitTracer { "file:/C:/gluegen/build-x86_64 öä lala/gluegen-rt.jar", "C:\\gluegen\\build-x86_64 öä lala\\gluegen-rt.jar"}, + new String[] {"\\\\filehost\\gluegen\\build-x86_64 öä lala\\gluegen-rt.jar", + "file://filehost/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar", + "file://filehost/gluegen/build-x86_64 öä lala/gluegen-rt.jar", + "\\\\filehost\\gluegen\\build-x86_64 öä lala\\gluegen-rt.jar"}, + /* No support for '#' fragment in URI path ! new String[] {"C:/gluegen/#/gluegen-rt.jar", "file:/C:/gluegen/%23/gluegen-rt.jar", @@ -364,22 +378,21 @@ public class TestIOUtilURIHandling extends JunitTracer { final File file = new File(fileSource); { final URI uri0 = file.toURI(); - System.err.println("uri.string: "+uri0.toString()); - System.err.println("uri.ascii : "+uri0.toASCIIString()); + System.err.println("uri0.string: "+uri0.toString()); + System.err.println("uri0.ascii : "+uri0.toASCIIString()); } - final URI uri0 = IOUtil.toURISimple(file); - System.err.println("uri.string: "+uri0.toString()); - System.err.println("uri.ascii : "+uri0.toASCIIString()); - showURI(uri0); - showURL(uri0.toURL()); + final URI uri1 = IOUtil.toURISimple(file); + System.err.println("uri1.string: "+uri1.toString()); + System.err.println("uri1.ascii : "+uri1.toASCIIString()); + showURI(uri1); + showURL(uri1.toURL()); - final URL actualUrl = IOUtil.toURL(uri0); + final URL actualUrl = IOUtil.toURL(uri1); final String actualUrlS = actualUrl.toExternalForm(); - final String actualUrlPathS = actualUrl.getPath(); - final String actualFilePathS = IOUtil.decodeURIToFilePath( actualUrlPathS ); - final boolean equalsFilePath = fileExpected.equals(actualFilePathS); - System.err.println("actual____url-path: "+actualUrlPathS); - System.err.println("actual___file-path: "+actualFilePathS); + final String actualFileS = IOUtil.decodeURIIfFilePath(uri1); + final boolean equalsFilePath = fileExpected.equals(actualFileS); + System.err.println("actual_______uri : "+actualUrlS); + System.err.println("actual___file-path: "+actualFileS); System.err.println("expected_path: "+fileExpected+" - "+(equalsFilePath?"OK":"ERROR")); final boolean equalsDecUri = uriDecExpected.equals(actualUrlS); System.err.println("actual_______uri: "+actualUrlS); |