File tree Expand file tree Collapse file tree 2 files changed +16
-9
lines changed
main/java/org/springframework/web/util
test/java/org/springframework/web/util Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -405,16 +405,17 @@ else if (index1 == requestUri.length()) {
405
405
* </ul>
406
406
*/
407
407
private static String getSanitizedPath (final String path ) {
408
- int index = path .indexOf ("//" );
409
- if (index >= 0 ) {
410
- StringBuilder sanitized = new StringBuilder (path );
411
- while (index != -1 ) {
412
- sanitized .deleteCharAt (index );
413
- index = sanitized .indexOf ("//" , index );
408
+ if (path .length () == 0 ) {
409
+ return path ;
410
+ }
411
+ char [] arr = path .toCharArray ();
412
+ int slowIndex = 0 ;
413
+ for (int fastIndex = 1 ; fastIndex < arr .length ; fastIndex ++) {
414
+ if (arr [fastIndex ] != '/' || arr [slowIndex ] != '/' ) {
415
+ arr [++slowIndex ] = arr [fastIndex ];
414
416
}
415
- return sanitized .toString ();
416
417
}
417
- return path ;
418
+ return new String ( arr , 0 , slowIndex + 1 ) ;
418
419
}
419
420
420
421
/**
@@ -532,7 +533,7 @@ public String getOriginatingServletPath(HttpServletRequest request) {
532
533
*/
533
534
public String getOriginatingQueryString (HttpServletRequest request ) {
534
535
if ((request .getAttribute (WebUtils .FORWARD_REQUEST_URI_ATTRIBUTE ) != null ) ||
535
- (request .getAttribute (WebUtils .ERROR_REQUEST_URI_ATTRIBUTE ) != null )) {
536
+ (request .getAttribute (WebUtils .ERROR_REQUEST_URI_ATTRIBUTE ) != null )) {
536
537
return (String ) request .getAttribute (WebUtils .FORWARD_QUERY_STRING_ATTRIBUTE );
537
538
}
538
539
else {
Original file line number Diff line number Diff line change @@ -246,6 +246,12 @@ void removeDuplicateSlashesInPath() {
246
246
request .setRequestURI ("/SPR-12372/foo/bar//" );
247
247
248
248
assertThat (helper .getLookupPathForRequest (request )).isEqualTo ("/foo/bar//" );
249
+
250
+ // "enhance" case
251
+ request .setServletPath ("/foo/bar//" );
252
+ request .setRequestURI ("/SPR-12372////////////////////////foo//////////////////bar////////////////////" );
253
+
254
+ assertThat (helper .getLookupPathForRequest (request )).isEqualTo ("/foo/bar//" );
249
255
}
250
256
251
257
@ Test
You can’t perform that action at this time.
0 commit comments