ResourceUrlProvider handles sanitizes double slashes
Issue: SPR-16296
This commit is contained in:
@@ -35,6 +35,9 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationCon
|
||||
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
/**
|
||||
@@ -136,6 +139,25 @@ public class ResourceUrlProviderTests {
|
||||
assertFalse(urlProviderBean.isAutodetect());
|
||||
}
|
||||
|
||||
@Test // SPR-16296
|
||||
public void getForLookupPathShouldNotFailIfPathContainsDoubleSlashes() {
|
||||
// given
|
||||
ResourceResolver mockResourceResolver = mock(ResourceResolver.class);
|
||||
when(mockResourceResolver.resolveUrlPath(any(), any(), any())).thenReturn("some-path");
|
||||
|
||||
ResourceHttpRequestHandler handler = new ResourceHttpRequestHandler();
|
||||
handler.getResourceResolvers().add(mockResourceResolver);
|
||||
|
||||
ResourceUrlProvider provider = new ResourceUrlProvider();
|
||||
provider.getHandlerMap().put("/some-pattern/**", handler);
|
||||
|
||||
// when
|
||||
String lookupForPath = provider.getForLookupPath("/some-pattern/some-lib//some-resource");
|
||||
|
||||
// then
|
||||
assertEquals("/some-pattern/some-path", lookupForPath);
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@SuppressWarnings({"unused", "WeakerAccess"})
|
||||
|
||||
Reference in New Issue
Block a user