Skip to content

Commit

Permalink
Fix how we handle "/" in non-leaf handlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
alesj committed Feb 13, 2009
1 parent bf93ee2 commit 1f9b8e2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
Expand Up @@ -252,7 +252,7 @@ private void init(URL localRootURL, VirtualFileHandler peer, ZipWrapper zipWrapp

// init initial root EntryInfo that will be overwritten
// if zip entry exists for rootEntryPath
entries.put("", new EntryInfo(new ZipEntryHandler(this, null, name, true), null));
entries.put("", new EntryInfo(new ZipEntryHandler(this, null, name, false), null));

// It's lazy init now
//initEntries();
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTest.java
Expand Up @@ -291,16 +291,27 @@ public void testTempUrls() throws Exception

VirtualFile ear = root.getChild("level1.zip");
VirtualFile earCopy = modify(ear);
assertEquals(ear.toURL(), earCopy.toURL());
assertEquals(getProtocol() + urlString + "level1.zip/", earCopy.toURL().toExternalForm());

VirtualFile o2 = ear.getChild("level2.zip");
VirtualFile l2 = earCopy.getChild("level2.zip");
assertEquals(o2.toURL(), l2.toURL());
assertEquals(getProtocol() + urlString + "level1.zip/level2.zip/", l2.toURL().toExternalForm());

VirtualFile o2sub = o2.getChild("test2.txt");
VirtualFile l2sub = l2.getChild("test2.txt");
assertEquals(o2sub.toURL(), l2sub.toURL());
assertEquals(getProtocol() + urlString + "level1.zip/level2.zip/test2.txt", l2sub.toURL().toExternalForm());

VirtualFile o3 = o2.getChild("level3.zip");
VirtualFile l3 = l2.getChild("level3.zip");
assertEquals(o3.toURL(), l3.toURL());
assertEquals(getProtocol() + urlString + "level1.zip/level2.zip/level3.zip/", l3.toURL().toExternalForm());

VirtualFile o3sub = o3.getChild("test3.txt");
VirtualFile l3sub = l3.getChild("test3.txt");
assertEquals(o3sub.toURL(), l3sub.toURL());
assertEquals(getProtocol() + urlString + "level1.zip/level2.zip/level3.zip/test3.txt", l3sub.toURL().toExternalForm());

ear.cleanup();
Expand Down
23 changes: 10 additions & 13 deletions src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
Expand Up @@ -860,7 +860,7 @@ public void testVFJarSerialization()
String name = tmpJar.getName();
String vfsPath = tmpJar.getPath();
vfsPath = vfsPath.substring(tmpRoot.getPath().length()+1);
URL url = new URL("vfs" + tmpJar.toURL());
URL url = new URL("vfs" + tmpJar.toURL() + "/");
//url = JarUtils.createJarURL(url);
log.debug("name: "+name);
log.debug("vfsPath: "+vfsPath);
Expand Down Expand Up @@ -1195,10 +1195,9 @@ public void testDirURLs() throws Exception
log.debug("outerURL: "+outerURL);
assertTrue(outerURL+" ends in '/'", outerURL.getPath().endsWith("/"));
// Validate that jar1 is under unpacked-outer.jar
URL jar1URL = new URL(outerURL, "jar1.jar");
URL jar1URL = new URL(outerURL, "jar1.jar/");
log.debug("jar1URL: "+jar1URL+", path="+jar1URL.getPath());
assertTrue("jar1URL path ends in unpacked-outer.jar/jar1.jar!/",
jar1URL.getPath().endsWith("unpacked-outer.jar/jar1.jar"));
assertTrue("jar1URL path ends in unpacked-outer.jar/jar1.jar!/", jar1URL.getPath().endsWith("unpacked-outer.jar/jar1.jar/"));
VirtualFile jar1 = outerJar.findChild("jar1.jar");
assertEquals(jar1URL.getPath(), jar1.toURL().getPath());

Expand All @@ -1224,17 +1223,15 @@ public void testDirURIs() throws Exception
log.debug("outerURI: "+outerURI);
assertTrue(outerURI+" ends in '/'", outerURI.getPath().endsWith("/"));
// Validate that jar1 is under unpacked-outer.jar
URI jar1URI = new URI(outerURI+"jar1.jar");
URI jar1URI = new URI(outerURI+"jar1.jar/");
log.debug("jar1URI: "+jar1URI+", path="+jar1URI.getPath());
assertTrue("jar1URI path ends in unpacked-outer.jar/jar1.jar!/",
jar1URI.getPath().endsWith("unpacked-outer.jar/jar1.jar"));
assertTrue("jar1URI path ends in unpacked-outer.jar/jar1.jar!/", jar1URI.getPath().endsWith("unpacked-outer.jar/jar1.jar/"));
VirtualFile jar1 = outerJar.findChild("jar1.jar");
assertEquals(jar1URI.getPath(), jar1.toURI().getPath());

VirtualFile packedJar = vfs.findChild("jar1.jar");
jar1URI = packedJar.findChild("org/jboss/test/vfs/support").toURI();
assertTrue("Jar directory entry URLs must end in /: " + jar1URI.toString(),
jar1URI.toString().endsWith("/"));
assertTrue("Jar directory entry URLs must end in /: " + jar1URI.toString(), jar1URI.toString().endsWith("/"));
}

/**
Expand Down Expand Up @@ -1391,17 +1388,17 @@ public void testJarWithSpacesInPath()
VirtualFile tstjar = vfs.findChild("path with spaces/tst.jar");
assertNotNull("tstjar != null", tstjar);
URI uri = tstjar.toURI();
URI expectedURI = new URI("vfs"+rootURL.toString()+"/path%20with%20spaces/tst.jar");
assertEquals(uri.getPath(), expectedURI.getPath());
URI expectedURI = new URI("vfs"+rootURL.toString()+"/path%20with%20spaces/tst.jar/");
assertEquals(expectedURI.getPath(), uri.getPath());

InputStream is = uri.toURL().openStream();
is.close();

tstjar = vfs.findChild("path with spaces/tst%20nospace.jar");
assertNotNull("tstjar != null", tstjar);
uri = tstjar.toURI();
expectedURI = new URI("vfs"+rootURL.toString()+"/path%20with%20spaces/tst%2520nospace.jar");
assertEquals(uri.getPath(), expectedURI.getPath());
expectedURI = new URI("vfs"+rootURL.toString()+"/path%20with%20spaces/tst%2520nospace.jar/");
assertEquals(expectedURI.getPath(), uri.getPath());

is = uri.toURL().openStream();
is.close();
Expand Down

0 comments on commit 1f9b8e2

Please sign in to comment.