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 ;
@@ -440,7 +442,11 @@ public Object merge(Object parent) {
440
442
if (parent == null ) {
441
443
return this ;
442
444
}
443
- if (parent instanceof RequestBuilder ) {
445
+ if (parent instanceof MockHttpServletRequestBuilder ) {
446
+ MockHttpServletRequestBuilder copiedParent = MockMvcRequestBuilders .get ("/" );
447
+ copiedParent .merge (parent );
448
+ this .parentBuilder = copiedParent ;
449
+ } else if (parent instanceof RequestBuilder ) {
444
450
this .parentBuilder = (RequestBuilder ) parent ;
445
451
}
446
452
if (parent instanceof SmartRequestBuilder ) {
Original file line number Diff line number Diff line change @@ -894,6 +894,20 @@ public void mergeRequestAttribute() throws Exception {
894
894
assertThat (mockMvc .perform (requestBuilder ).andReturn ().getRequest ().getAttribute (attrName ), equalTo (attrValue ));
895
895
}
896
896
897
+ @ Test // SPR-14584
898
+ public void mergeDoesNotCorruptPathInfoOnParent () throws Exception {
899
+ String pathInfo = "/foo/bar" ;
900
+ MockMvc mockMvc = MockMvcBuilders .standaloneSetup (new HelloController ())
901
+ .defaultRequest (get ("/" ))
902
+ .build ();
903
+
904
+ assertThat (mockMvc .perform (get (pathInfo )).andReturn ().getRequest ().getPathInfo (), equalTo (pathInfo ));
905
+
906
+ mockMvc .perform (requestBuilder );
907
+
908
+ assertThat (mockMvc .perform (get (pathInfo )).andReturn ().getRequest ().getPathInfo (), equalTo (pathInfo ));
909
+ }
910
+
897
911
898
912
private void assertSingleSessionCookie (String expected ) {
899
913
com .gargoylesoftware .htmlunit .util .Cookie jsessionidCookie = webClient .getCookieManager ().getCookie ("JSESSIONID" );
You can’t perform that action at this time.
0 commit comments