diff --git a/spring-core/src/main/java/org/springframework/core/io/UrlResource.java b/spring-core/src/main/java/org/springframework/core/io/UrlResource.java index 6c5f2f5878a..c3d440c4786 100644 --- a/spring-core/src/main/java/org/springframework/core/io/UrlResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/UrlResource.java @@ -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()); } /** diff --git a/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java b/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java index bb487fad984..d46500f87e4 100644 --- a/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java @@ -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 {