Make PathResource UNC compatible again

The newly added checkAliasPath used the File constructor on a uri
resulting from Path's toUri, which caused an IllegalArgumentException due to
the uri having an authority component. (File's toURI and Path's toUri
differ slightly wrt. UNC paths; file:////unc vs file://unc.)

Signed-off-by: Fabian van der Veen <djyhnzo@gmail.com>
This commit is contained in:
Fabian van der Veen 2017-03-30 16:03:11 +02:00
parent daf61cd294
commit 9a00c038ff
2 changed files with 18 additions and 3 deletions

View File

@ -73,7 +73,7 @@ public class PathResource extends Resource
if(!URIUtil.equalsIgnoreEncodings(uri,path.toUri()))
{
return new File(uri).toPath().toAbsolutePath();
return Paths.get(uri).toAbsolutePath();
}
if (!abs.isAbsolute())
@ -568,4 +568,4 @@ public class PathResource extends Resource
{
return this.uri.toASCIIString();
}
}
}

View File

@ -29,6 +29,7 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeNoException;
import static org.junit.Assume.assumeThat;
import static org.junit.Assume.assumeTrue;
import java.io.BufferedWriter;
import java.io.File;
@ -1397,5 +1398,19 @@ public class FileSystemResourceTest
}
}
@Test
public void testUncPath() throws Exception
{
assumeTrue("Only windows supports UNC paths", OS.IS_WINDOWS);
assumeFalse("FileResource does not support this test", _class.equals(FileResource.class));
try (Resource base = newResource(URI.create("file://127.0.0.1/path")))
{
Resource resource = base.addPath("WEB-INF/");
assertThat("getURI()", resource.getURI().toASCIIString(), containsString("path/WEB-INF/"));
assertThat("isAlias()", resource.isAlias(), is(true));
assertThat("getAlias()", resource.getAlias(), notNullValue());
assertThat("getAlias()", resource.getAlias().toASCIIString(), containsString("path/WEB-INF"));
}
}
}