UrlResource applies StringUtils.getFilename against URL path
Issue: SPR-15411
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -239,12 +239,11 @@ public class UrlResource extends AbstractFileResolvingResource {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This implementation returns the name of the file that this URL refers to.
|
* This implementation returns the name of the file that this URL refers to.
|
||||||
* @see java.net.URL#getFile()
|
* @see java.net.URL#getPath()
|
||||||
* @see java.io.File#getName()
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getFilename() {
|
public String getFilename() {
|
||||||
return new File(this.url.getFile()).getName();
|
return StringUtils.getFilename(this.url.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -133,8 +133,13 @@ public class ResourceTests {
|
|||||||
Resource resource = new UrlResource(getClass().getResource("Resource.class"));
|
Resource resource = new UrlResource(getClass().getResource("Resource.class"));
|
||||||
doTestResource(resource);
|
doTestResource(resource);
|
||||||
assertEquals(new UrlResource(getClass().getResource("Resource.class")), resource);
|
assertEquals(new UrlResource(getClass().getResource("Resource.class")), resource);
|
||||||
|
|
||||||
Resource resource2 = new UrlResource("file:core/io/Resource.class");
|
Resource resource2 = new UrlResource("file:core/io/Resource.class");
|
||||||
assertEquals(resource2, new UrlResource("file:core/../core/io/./Resource.class"));
|
assertEquals(resource2, new UrlResource("file:core/../core/io/./Resource.class"));
|
||||||
|
|
||||||
|
assertEquals("test.txt", new UrlResource("file:/dir/test.txt?argh").getFilename());
|
||||||
|
assertEquals("test.txt", new UrlResource("file:\\dir\\test.txt?argh").getFilename());
|
||||||
|
assertEquals("test.txt", new UrlResource("file:\\dir/test.txt?argh").getFilename());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTestResource(Resource resource) throws IOException {
|
private void doTestResource(Resource resource) throws IOException {
|
||||||
|
|||||||
Reference in New Issue
Block a user