UrlResource applies StringUtils.getFilename against URL path

Issue: SPR-15411
This commit is contained in:
Juergen Hoeller 2017-04-06 14:07:22 +02:00
parent 3037277d0e
commit 75dd8d9c06
2 changed files with 9 additions and 5 deletions

View File

@ -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");
* 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.
* @see java.net.URL#getFile()
* @see java.io.File#getName()
* @see java.net.URL#getPath()
*/
@Override
public String getFilename() {
return new File(this.url.getFile()).getName();
return StringUtils.getFilename(this.url.getPath());
}
/**

View File

@ -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");
* 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"));
doTestResource(resource);
assertEquals(new UrlResource(getClass().getResource("Resource.class")), resource);
Resource resource2 = new UrlResource("file: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 {