-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
Igor E. Poteryaev opened SPR-5115 and commented
Protected constructor in ClassPathResource, which is called from createRelative() does not clean path parameter as public constructors do.
I think that it is inconsistent and add unneeded complication in createRelative() API usage.
Supposed fix is 1-liner. Change line 107 in org.springframework.core.io.ClassPathResource.java
from
this.path = path;
to
this.path = StringUtils.cleanPath(path);
And add test for this fix to org.springframework.core.io.ResourceTests method testClassPathResource():
public void testClassPathResource() throws IOException {
Resource resource = new ClassPathResource("org/springframework/core/io/Resource.class");
doTestResource(resource);
Resource resource2 = new ClassPathResource("org/springframework/core/../core/io/./Resource.class");
assertEquals(resource, resource2);
//++++
Resource resource3 = new ClassPathResource("org/springframework/core/").createRelative("../core/io/./Resource.class");
assertEquals(resource, resource3);
//====
// Check whether equal/hashCode works in a HashSet.
HashSet resources = new HashSet();
resources.add(resource);
resources.add(resource2);
assertEquals(1, resources.size());
}
Cheers,
Igor.
Affects: 2.5.5