|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2017 the original author or authors. |
| 2 | + * Copyright 2002-2018 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
33 | 33 | import org.springframework.mock.web.test.MockHttpServletResponse;
|
34 | 34 | import org.springframework.util.MultiValueMap;
|
35 | 35 |
|
36 |
| -import static org.junit.Assert.assertEquals; |
| 36 | +import static org.junit.Assert.*; |
37 | 37 |
|
38 | 38 | /**
|
39 | 39 | * Unit tests for {@link AbstractServerHttpRequest}.
|
@@ -85,26 +85,33 @@ public void queryParamsWithNoValue() throws Exception {
|
85 | 85 | assertEquals(Collections.singletonList(null), params.get("a"));
|
86 | 86 | }
|
87 | 87 |
|
| 88 | + @Test // SPR-16434 |
| 89 | + public void mutatePathWithEncodedQueryParams() throws Exception { |
| 90 | + ServerHttpRequest request = createHttpRequest("/path?name=%E6%89%8E%E6%A0%B9") |
| 91 | + .mutate().path("/mutatedPath").build(); |
| 92 | + assertEquals("/mutatedPath", request.getURI().getRawPath()); |
| 93 | + assertEquals("name=%E6%89%8E%E6%A0%B9", request.getURI().getRawQuery()); |
| 94 | + } |
| 95 | + |
| 96 | + |
88 | 97 | private ServerHttpRequest createHttpRequest(String path) throws Exception {
|
89 |
| - HttpServletRequest request = new MockHttpServletRequest("GET", path) { |
90 |
| - @Override |
91 |
| - public ServletInputStream getInputStream() { |
92 |
| - return new TestServletInputStream(); |
93 |
| - } |
94 |
| - }; |
| 98 | + HttpServletRequest request = createEmptyBodyHttpServletRequest(path); |
95 | 99 | AsyncContext asyncContext = new MockAsyncContext(request, new MockHttpServletResponse());
|
96 | 100 | return new ServletServerHttpRequest(request, asyncContext, "", new DefaultDataBufferFactory(), 1024);
|
97 | 101 | }
|
98 | 102 |
|
99 |
| - private static class TestServletInputStream extends DelegatingServletInputStream { |
100 |
| - |
101 |
| - public TestServletInputStream() { |
102 |
| - super(new ByteArrayInputStream(new byte[0])); |
103 |
| - } |
104 |
| - |
105 |
| - @Override |
106 |
| - public void setReadListener(ReadListener readListener) { |
107 |
| - // Ignore |
108 |
| - } |
| 103 | + private HttpServletRequest createEmptyBodyHttpServletRequest(String path) { |
| 104 | + return new MockHttpServletRequest("GET", path) { |
| 105 | + @Override |
| 106 | + public ServletInputStream getInputStream() { |
| 107 | + return new DelegatingServletInputStream(new ByteArrayInputStream(new byte[0])) { |
| 108 | + @Override |
| 109 | + public void setReadListener(ReadListener readListener) { |
| 110 | + // Ignore |
| 111 | + } |
| 112 | + }; |
| 113 | + } |
| 114 | + }; |
109 | 115 | }
|
| 116 | + |
110 | 117 | }
|
0 commit comments