[PATCH] Fixed jcifs.smb.Handler to parse .# and ..# specs
Jim Hurne
hurne at vivisimo.com
Wed Sep 1 12:59:57 MDT 2010
---
src/jcifs/smb/Handler.java | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/src/jcifs/smb/Handler.java b/src/jcifs/smb/Handler.java
index bb75090..85cd035 100644
--- a/src/jcifs/smb/Handler.java
+++ b/src/jcifs/smb/Handler.java
@@ -48,9 +48,20 @@ public class Handler extends URLStreamHandler {
spec = "//" + spec;
limit += 2;
}
- super.parseURL( u, spec, start, limit );
+ String mSpec = spec;
+ if(spec.contains("..#")) {
+ int hashStart = spec.indexOf("..#");
+ mSpec = spec.substring(0, hashStart) + spec.substring(hashStart + 2);
+ limit -= 2;
+ }
+ super.parseURL( u, mSpec, start, limit );
path = u.getPath();
ref = u.getRef();
+ if (spec.contains("..#" + ref)) {
+ path += "..";
+ } else if (spec.contains(".#" + ref) && !path.endsWith(".")) {
+ path += ".";
+ }
if (ref != null) {
path += '#' + ref;
}
--
1.7.0.4
------=_Part_72_18673477.1283369671401
Content-Type: text/x-java; name=SmbUrlTest.java
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=SmbUrlTest.java
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class SmbUrlTest {
private static final String CONTEXT_PATH = "smb://some-share/test/dir/";
private String child;
private String expected;
@Parameters
public static Collection<Object[]> parameters() throws Exception
{
return Arrays.asList(new Object[][] {
// Normal file names
{"smb://", "smb://"},
{"smb://some:23345/share", "smb://some:23345/share"},
{"normal.txt", "smb://some-share/test/dir/normal.txt"},
{"/normal.txt", "smb://some-share/normal.txt"},
{"subdir/", "smb://some-share/test/dir/subdir/"},
{"/subdir/", "smb://some-share/subdir/"},
{"subdir/normal.txt", "smb://some-share/test/dir/subdir/normal.txt"},
// File names with hashes
{"no#rmal.txt", "smb://some-share/test/dir/no#rmal.txt"},
{"#subdir/", "smb://some-share/test/dir/#subdir/"},
{"su#bdir/", "smb://some-share/test/dir/su#bdir/"},
{"subdir/#normal.txt", "smb://some-share/test/dir/subdir/#normal.txt"},
// File names with dots and hashes
{".#onedot", "smb://some-share/test/dir/.#onedot"},
{"..#twodots", "smb://some-share/test/dir/..#twodots"},
{".#onedot/", "smb://some-share/test/dir/.#onedot/"},
{"..#twodots/", "smb://some-share/test/dir/..#twodots/"},
{"/.#onedot", "smb://some-share/.#onedot"},
{"/..#twodots", "smb://some-share/..#twodots"},
{"prefix..#twodots", "smb://some-share/test/dir/prefix..#twodots"},
{"subdir/.#onedot", "smb://some-share/test/dir/subdir/.#onedot"},
{"subdir/..#twodots", "smb://some-share/test/dir/subdir/..#twodots"},
{"subdir/.#onedot/another-dir/", "smb://some-share/test/dir/subdir/.#onedot/another-dir/"},
{"subdir/..#twodots/another-dir/", "smb://some-share/test/dir/subdir/..#twodots/another-dir/"},
{".#onedot/.#onedot", "smb://some-share/test/dir/.#onedot/.#onedot"},
{"..#twodots/..#twodots", "smb://some-share/test/dir/..#twodots/..#twodots"},
{"..#twodots/.#onedot", "smb://some-share/test/dir/..#twodots/.#onedot"},
{".#onedot/..#twodots", "smb://some-share/test/dir/.#onedot/..#twodots"},
{"../.#onedot", "smb://some-share/test/.#onedot"},
{"../..#twodots", "smb://some-share/test/..#twodots"},
{"./.#onedot", "smb://some-share/test/dir/.#onedot"},
{"./..#twodots", "smb://some-share/test/dir/..#twodots"},
{"smb://share/.#onedot", "smb://share/.#onedot"},
{"smb://share/..#twodots", "smb://share/..#twodots"},
{"smb://share:65674/.#onedot", "smb://share:65674/.#onedot"},
{"smb://share:65674/..#twodots", "smb://share:65674/..#twodots"},
{"smb://share/test/dir/.#onedot", "smb://share/test/dir/.#onedot"},
{"smb://share/test/dir/..#twodots", "smb://share/test/dir/..#twodots"},
{"smb://share:65674/test/dir/.#onedot", "smb://share:65674/test/dir/.#onedot"},
{"smb://share:65674/test/dir/..#twodots", "smb://share:65674/test/dir/..#twodots"},
});
}
@BeforeClass
public static void registerSmbProtocol() {
jcifs.Config.registerSmbURLHandler();
}
public SmbUrlTest(String child, String expected) throws MalformedURLException {
this.child = child;
this.expected = expected;
}
@Test
public void constructsUrls() throws Exception {
// This test is only valid for data that starts with "smb:"
if(child.contains("smb:")) {
URL newUrl = new URL(child);
assertThat(newUrl.toString(), is(expected));
}
}
@Test
public void constructsUrlsWithContext() throws Exception {
URL context = new URL(CONTEXT_PATH);
URL newUrl = new URL(context, child);
assertThat(newUrl.toString(), is(expected));
}
}
------=_Part_72_18673477.1283369671401--
More information about the jCIFS
mailing list