File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
main/java/org/springframework/test/web/servlet/htmlunit
test/java/org/springframework/test/web/servlet/htmlunit Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 45
45
import org .springframework .mock .web .MockHttpSession ;
46
46
import org .springframework .test .web .servlet .RequestBuilder ;
47
47
import org .springframework .test .web .servlet .SmartRequestBuilder ;
48
+ import org .springframework .test .web .servlet .request .MockHttpServletRequestBuilder ;
49
+ import org .springframework .test .web .servlet .request .MockMvcRequestBuilders ;
48
50
import org .springframework .test .web .servlet .request .RequestPostProcessor ;
49
51
import org .springframework .util .Assert ;
50
52
import org .springframework .util .ObjectUtils ;
@@ -435,7 +437,11 @@ public Object merge(Object parent) {
435
437
if (parent == null ) {
436
438
return this ;
437
439
}
438
- if (parent instanceof RequestBuilder ) {
440
+ if (parent instanceof MockHttpServletRequestBuilder ) {
441
+ MockHttpServletRequestBuilder copiedParent = MockMvcRequestBuilders .get ("/" );
442
+ copiedParent .merge (parent );
443
+ this .parentBuilder = copiedParent ;
444
+ } else if (parent instanceof RequestBuilder ) {
439
445
this .parentBuilder = (RequestBuilder ) parent ;
440
446
}
441
447
if (parent instanceof SmartRequestBuilder ) {
Original file line number Diff line number Diff line change @@ -895,6 +895,20 @@ public void mergeRequestAttribute() throws Exception {
895
895
assertThat (mockMvc .perform (requestBuilder ).andReturn ().getRequest ().getAttribute (attrName ), equalTo (attrValue ));
896
896
}
897
897
898
+ @ Test // SPR-14584
899
+ public void mergeDoesNotCorruptPathInfoOnParent () throws Exception {
900
+ String pathInfo = "/foo/bar" ;
901
+ MockMvc mockMvc = MockMvcBuilders .standaloneSetup (new HelloController ())
902
+ .defaultRequest (get ("/" ))
903
+ .build ();
904
+
905
+ assertThat (mockMvc .perform (get (pathInfo )).andReturn ().getRequest ().getPathInfo (), equalTo (pathInfo ));
906
+
907
+ mockMvc .perform (requestBuilder );
908
+
909
+ assertThat (mockMvc .perform (get (pathInfo )).andReturn ().getRequest ().getPathInfo (), equalTo (pathInfo ));
910
+ }
911
+
898
912
899
913
private void assertSingleSessionCookie (String expected ) {
900
914
com .gargoylesoftware .htmlunit .util .Cookie jsessionidCookie = webClient .getCookieManager ().getCookie ("JSESSIONID" );
You can’t perform that action at this time.
0 commit comments