diff options
author | Sven Gothel <[email protected]> | 2015-10-03 11:44:02 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-10-03 11:44:02 +0200 |
commit | 026875dd5256051d4e3504f1d9b01f7ce2bb70ff (patch) | |
tree | d7d1bd386c870787ffcf737ca6baaeaa6f73ef11 /src/junit/com | |
parent | 48cef027ec727d3e03b78f577208d1ce10b705d1 (diff) |
Bug 1243 - Fix IOUtil.cleanPathString(..) special case ; Allow IOUtil and Uri to handle relative path
Fix IOUtil.cleanPathString(..) special case:
Special case '/a/./../b' -> '/b'
requires to resolve './' before '../'.
Allow IOUtil and Uri to handle relative path:
- IOUtil.getParentOf(..)
- IOUtil.cleanPathString(..)
Handle cases:
'a/./../b' -> 'b'
'.././b' -> '../b'
- Uri: Handle null scheme
Diffstat (limited to 'src/junit/com')
-rw-r--r-- | src/junit/com/jogamp/common/net/TestUri01.java | 32 | ||||
-rw-r--r-- | src/junit/com/jogamp/common/util/TestIOUtil01.java | 88 |
2 files changed, 115 insertions, 5 deletions
diff --git a/src/junit/com/jogamp/common/net/TestUri01.java b/src/junit/com/jogamp/common/net/TestUri01.java index 1173610..4205de1 100644 --- a/src/junit/com/jogamp/common/net/TestUri01.java +++ b/src/junit/com/jogamp/common/net/TestUri01.java @@ -248,6 +248,20 @@ public class TestUri01 extends SingletonJunitCase { @Test public void test08NormalizedHierarchy() throws IOException, URISyntaxException { { + final Uri input = Uri.cast("./dummy/nop/../a.txt"); + final Uri expected = Uri.cast("dummy/a.txt"); + URIDumpUtil.showUri(input); + final Uri normal = input.getNormalized(); + Assert.assertEquals(expected, normal); + } + { + final Uri input = Uri.cast("../dummy/nop/../a.txt"); + final Uri expected = Uri.cast("../dummy/a.txt"); + URIDumpUtil.showUri(input); + final Uri normal = input.getNormalized(); + Assert.assertEquals(expected, normal); + } + { final Uri input = Uri.cast("http://localhost/dummy/../"); final Uri expected = Uri.cast("http://localhost/"); URIDumpUtil.showUri(input); @@ -255,7 +269,21 @@ public class TestUri01 extends SingletonJunitCase { Assert.assertEquals(expected, normal); } { - final Uri input = Uri.cast("http://localhost/test/dummy/../text.txt"); + final Uri input = Uri.cast("http://localhost/dummy/./../"); + final Uri expected = Uri.cast("http://localhost/"); + URIDumpUtil.showUri(input); + final Uri normal = input.getNormalized(); + Assert.assertEquals(expected, normal); + } + { + final Uri input = Uri.cast("http://localhost/dummy/../aa/././../"); + final Uri expected = Uri.cast("http://localhost/"); + URIDumpUtil.showUri(input); + final Uri normal = input.getNormalized(); + Assert.assertEquals(expected, normal); + } + { + final Uri input = Uri.cast("http://localhost/test/dummy/./../text.txt"); final Uri expected = Uri.cast("http://localhost/test/text.txt"); URIDumpUtil.showUri(input); final Uri normal = input.getNormalized(); @@ -280,7 +308,7 @@ public class TestUri01 extends SingletonJunitCase { Assert.assertEquals(expected, normal); } { - final Uri input = Uri.cast("jar:http://localhost/test/dummy/../abc.jar!/"); + final Uri input = Uri.cast("jar:http://localhost/test/./dummy/../abc.jar!/"); final Uri expected = Uri.cast("jar:http://localhost/test/abc.jar!/"); URIDumpUtil.showUri(input); final Uri normal = input.getNormalized(); diff --git a/src/junit/com/jogamp/common/util/TestIOUtil01.java b/src/junit/com/jogamp/common/util/TestIOUtil01.java index be0c9a4..19bc8b0 100644 --- a/src/junit/com/jogamp/common/util/TestIOUtil01.java +++ b/src/junit/com/jogamp/common/util/TestIOUtil01.java @@ -35,6 +35,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.net.URISyntaxException; import java.net.URLConnection; import java.nio.ByteBuffer; @@ -43,6 +44,9 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import com.jogamp.common.ExceptionUtils; +import com.jogamp.common.net.URIDumpUtil; +import com.jogamp.common.net.Uri; import com.jogamp.common.os.MachineDataInfo; import com.jogamp.common.os.Platform; import com.jogamp.junit.util.SingletonJunitCase; @@ -78,7 +82,85 @@ public class TestIOUtil01 extends SingletonJunitCase { } @Test - public void testCopyStream01Array() throws IOException { + public void test01CleanPathString() throws IOException, URISyntaxException { + { + final String input = "./dummy/nop/../a.txt"; + final String expected = "dummy/a.txt"; + Assert.assertEquals(expected, IOUtil.cleanPathString(input)); + } + { + final String input = "../dummy/nop/../a.txt"; + final String expected = "../dummy/a.txt"; + Assert.assertEquals(expected, IOUtil.cleanPathString(input)); + } + { + final String input = ".././dummy/nop/../a.txt"; + final String expected = "../dummy/a.txt"; + Assert.assertEquals(expected, IOUtil.cleanPathString(input)); + } + { + final String input = "./../dummy/nop/../a.txt"; + final String expected = "../dummy/a.txt"; + Assert.assertEquals(expected, IOUtil.cleanPathString(input)); + } + { + final String input = "../dummy/./nop/../a.txt"; + final String expected = "../dummy/a.txt"; + Assert.assertEquals(expected, IOUtil.cleanPathString(input)); + } + { + final String input = "/dummy/nop/./../a.txt"; + final String expected = "/dummy/a.txt"; + Assert.assertEquals(expected, IOUtil.cleanPathString(input)); + } + { + final String input = "dummy/../nop/./.././aaa/bbb/../../a.txt"; + final String expected = "a.txt"; + Assert.assertEquals(expected, IOUtil.cleanPathString(input)); + } + { + final String input = "/dummy/../nop/./.././aaa/bbb/././ccc/../../../a.txt"; + final String expected = "/a.txt"; + Assert.assertEquals(expected, IOUtil.cleanPathString(input)); + } + { + URISyntaxException use = null; + try { + // Error case! + final String input = "../../error.txt"; + final String expected = "error.txt"; + final String result = IOUtil.cleanPathString(input); // URISyntaxException + System.err.println("input : "+input); + System.err.println("expected: "+expected); + System.err.println("result : "+result); + Assert.assertEquals(expected, result); + } catch (final URISyntaxException _use) { + use = _use; + ExceptionUtils.dumpThrowable("", _use, 0, 3); + } + Assert.assertNotNull("URISyntaxException expected", use); + } + { + URISyntaxException use = null; + try { + // Error case! + final String input = ".././a/../../error.txt"; + final String expected = "error.txt"; + final String result = IOUtil.cleanPathString(input); // URISyntaxException + System.err.println("input : "+input); + System.err.println("expected: "+expected); + System.err.println("result : "+result); + Assert.assertEquals(expected, result); + } catch (final URISyntaxException _use) { + use = _use; + ExceptionUtils.dumpThrowable("", _use, 0, 3); + } + Assert.assertNotNull("URISyntaxException expected", use); + } + } + + @Test + public void test11CopyStream01Array() throws IOException { final URLConnection urlConn = IOUtil.getResource(tfilename, this.getClass().getClassLoader(), this.getClass()); Assert.assertNotNull(urlConn); final BufferedInputStream bis = new BufferedInputStream( urlConn.getInputStream() ); @@ -94,7 +176,7 @@ public class TestIOUtil01 extends SingletonJunitCase { } @Test - public void testCopyStream02Buffer() throws IOException { + public void test12CopyStream02Buffer() throws IOException { final URLConnection urlConn = IOUtil.getResource(tfilename, this.getClass().getClassLoader(), this.getClass()); Assert.assertNotNull(urlConn); final BufferedInputStream bis = new BufferedInputStream( urlConn.getInputStream() ); @@ -111,7 +193,7 @@ public class TestIOUtil01 extends SingletonJunitCase { } @Test - public void testCopyStream03Buffer() throws IOException { + public void test13CopyStream03Buffer() throws IOException { final String tfilename2 = "./test2.bin" ; final URLConnection urlConn1 = IOUtil.getResource(tfilename, this.getClass().getClassLoader(), this.getClass()); Assert.assertNotNull(urlConn1); |