Fix trailing slash issue
Issue: SPR-15201
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -153,6 +153,21 @@ public class RestTemplateTests {
|
||||
verify(response).close();
|
||||
}
|
||||
|
||||
@Test // SPR-15201
|
||||
public void uriTemplateWithTrailingSlash() throws Exception {
|
||||
String url = "http://example.com/spring/";
|
||||
given(requestFactory.createRequest(new URI(url), HttpMethod.GET)).willReturn(request);
|
||||
given(request.execute()).willReturn(response);
|
||||
given(errorHandler.hasError(response)).willReturn(false);
|
||||
HttpStatus status = HttpStatus.OK;
|
||||
given(response.getStatusCode()).willReturn(status);
|
||||
given(response.getStatusText()).willReturn(status.getReasonPhrase());
|
||||
|
||||
template.execute(url, HttpMethod.GET, null, null);
|
||||
|
||||
verify(response).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void errorHandling() throws Exception {
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.GET)).willReturn(request);
|
||||
|
||||
@@ -127,10 +127,32 @@ public class DefaultUriBuilderFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialPathSplitIntoPathSegments() throws Exception {
|
||||
public void parsePathWithDefaultSettings() throws Exception {
|
||||
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("/foo/{bar}");
|
||||
URI uri = factory.uriString("/baz/{id}").build("a/b", "c/d");
|
||||
assertEquals("/foo/a%2Fb/baz/c%2Fd", uri.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parsePathIsTurnedOff() throws Exception {
|
||||
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("/foo/{bar}");
|
||||
factory.setParsePath(false);
|
||||
URI uri = factory.uriString("/baz/{id}").build("a/b", "c/d");
|
||||
assertEquals("/foo/a/b/baz/c/d", uri.toString());
|
||||
}
|
||||
|
||||
@Test // SPR-15201
|
||||
public void pathWithTrailingSlash() throws Exception {
|
||||
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory();
|
||||
URI uri = factory.expand("http://localhost:8080/spring/");
|
||||
assertEquals("http://localhost:8080/spring/", uri.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathWithDuplicateSlashes() throws Exception {
|
||||
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory();
|
||||
URI uri = factory.expand("/foo/////////bar");
|
||||
assertEquals("/foo/bar", uri.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user