File tree Expand file tree Collapse file tree 3 files changed +30
-5
lines changed
main/java/org/springframework/test/web/servlet/request
test/java/org/springframework/test/web Expand file tree Collapse file tree 3 files changed +30
-5
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2021 the original author or authors.
2
+ * Copyright 2002-2022 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.
@@ -148,7 +148,7 @@ public class MockHttpServletRequestBuilder
148
148
149
149
private static URI initUri (String url , Object [] vars ) {
150
150
Assert .notNull (url , "'url' must not be null" );
151
- Assert .isTrue (url .startsWith ("/" ) || url .startsWith ("http://" ) || url .startsWith ("https://" ), "" +
151
+ Assert .isTrue (url .isEmpty () || url . startsWith ("/" ) || url .startsWith ("http://" ) || url .startsWith ("https://" ),
152
152
"'url' should start with a path or be a complete HTTP URL: " + url );
153
153
return UriComponentsBuilder .fromUriString (url ).buildAndExpand (vars ).encode ().toUri ();
154
154
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2020 the original author or authors.
2
+ * Copyright 2002-2022 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.
@@ -50,6 +50,15 @@ public void controller() {
50
50
.expectBody (String .class ).isEqualTo ("Success" );
51
51
}
52
52
53
+ @ Test
54
+ public void controllerEmptyPath () {
55
+ new DefaultControllerSpec (new MyController ()).build ()
56
+ .get ().uri ("" )
57
+ .exchange ()
58
+ .expectStatus ().isOk ()
59
+ .expectBody (String .class ).isEqualTo ("Success empty path" );
60
+ }
61
+
53
62
@ Test
54
63
public void controllerAdvice () {
55
64
new DefaultControllerSpec (new MyController ())
@@ -116,10 +125,15 @@ public void uriTemplate() {
116
125
private static class MyController {
117
126
118
127
@ GetMapping ("/" )
119
- public String handle () {
128
+ public String handleRootPath () {
120
129
return "Success" ;
121
130
}
122
131
132
+ @ GetMapping
133
+ public String handleEmptyPath () {
134
+ return "Success empty path" ;
135
+ }
136
+
123
137
@ GetMapping ("/exception" )
124
138
public void handleWithError () {
125
139
throw new IllegalStateException ();
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2021 the original author or authors.
2
+ * Copyright 2002-2022 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.
@@ -165,6 +165,17 @@ void contextPathServletPathInfo() {
165
165
assertThat (request .getPathInfo ()).isNull ();
166
166
}
167
167
168
+ @ Test // gh-28823
169
+ void emptyPath () {
170
+ this .builder = new MockHttpServletRequestBuilder (HttpMethod .GET , "" );
171
+ MockHttpServletRequest request = this .builder .buildRequest (this .servletContext );
172
+
173
+ assertThat (request .getRequestURI ()).isEqualTo ("" );
174
+ assertThat (request .getContextPath ()).isEqualTo ("" );
175
+ assertThat (request .getServletPath ()).isEqualTo ("" );
176
+ assertThat (request .getPathInfo ()).isNull ();
177
+ }
178
+
168
179
@ Test // SPR-16453
169
180
void pathInfoIsDecoded () {
170
181
this .builder = new MockHttpServletRequestBuilder (HttpMethod .GET , "/travel/hotels 42" );
You can’t perform that action at this time.
0 commit comments