File tree 4 files changed +34
-28
lines changed
spring-webflux/src/main/java/org/springframework/web/reactive
spring-webmvc/src/main/java/org/springframework/web/servlet
4 files changed +34
-28
lines changed Original file line number Diff line number Diff line change @@ -149,21 +149,22 @@ else if (path.charAt(i) > ' ' && path.charAt(i) != 127) {
149
149
150
150
private static String normalizePath (String path ) {
151
151
String result = path ;
152
+ result = decode (result );
152
153
if (result .contains ("%" )) {
153
154
result = decode (result );
154
- if ( result . contains ( "%" )) {
155
- result = decode ( result );
156
- }
157
- if ( result . contains ( "../" )) {
158
- return StringUtils . cleanPath (result );
159
- }
155
+ }
156
+ if (! StringUtils . hasText ( result )) {
157
+ return result ;
158
+ }
159
+ if (result . contains ( "../" )) {
160
+ return StringUtils . cleanPath ( result );
160
161
}
161
162
return path ;
162
163
}
163
164
164
165
private static String decode (String path ) {
165
166
try {
166
- return URLDecoder .decode (path , StandardCharsets .UTF_8 );
167
+ return UriUtils .decode (path , StandardCharsets .UTF_8 );
167
168
}
168
169
catch (Exception ex ) {
169
170
return "" ;
Original file line number Diff line number Diff line change 56
56
import org .springframework .web .server .MethodNotAllowedException ;
57
57
import org .springframework .web .server .ServerWebExchange ;
58
58
import org .springframework .web .server .WebHandler ;
59
+ import org .springframework .web .util .UriUtils ;
59
60
import org .springframework .web .util .pattern .PathPattern ;
60
61
61
62
/**
@@ -568,21 +569,22 @@ else if (path.charAt(i) > ' ' && path.charAt(i) != 127) {
568
569
569
570
private static String normalizePath (String path ) {
570
571
String result = path ;
572
+ result = decode (result );
571
573
if (result .contains ("%" )) {
572
574
result = decode (result );
573
- if ( result . contains ( "%" )) {
574
- result = decode ( result );
575
- }
576
- if ( result . contains ( "../" )) {
577
- return StringUtils . cleanPath (result );
578
- }
575
+ }
576
+ if (! StringUtils . hasText ( result )) {
577
+ return result ;
578
+ }
579
+ if (result . contains ( "../" )) {
580
+ return StringUtils . cleanPath ( result );
579
581
}
580
582
return path ;
581
583
}
582
584
583
585
private static String decode (String path ) {
584
586
try {
585
- return URLDecoder .decode (path , StandardCharsets .UTF_8 );
587
+ return UriUtils .decode (path , StandardCharsets .UTF_8 );
586
588
}
587
589
catch (Exception ex ) {
588
590
return "" ;
Original file line number Diff line number Diff line change @@ -150,21 +150,22 @@ else if (path.charAt(i) > ' ' && path.charAt(i) != 127) {
150
150
151
151
private static String normalizePath (String path ) {
152
152
String result = path ;
153
+ result = decode (result );
153
154
if (result .contains ("%" )) {
154
155
result = decode (result );
155
- if ( result . contains ( "%" )) {
156
- result = decode ( result );
157
- }
158
- if ( result . contains ( "../" )) {
159
- return StringUtils . cleanPath (result );
160
- }
156
+ }
157
+ if (! StringUtils . hasText ( result )) {
158
+ return result ;
159
+ }
160
+ if (result . contains ( "../" )) {
161
+ return StringUtils . cleanPath ( result );
161
162
}
162
163
return path ;
163
164
}
164
165
165
166
private static String decode (String path ) {
166
167
try {
167
- return URLDecoder .decode (path , StandardCharsets .UTF_8 );
168
+ return UriUtils .decode (path , StandardCharsets .UTF_8 );
168
169
}
169
170
catch (Exception ex ) {
170
171
return "" ;
Original file line number Diff line number Diff line change 63
63
import org .springframework .web .cors .CorsConfigurationSource ;
64
64
import org .springframework .web .servlet .HandlerMapping ;
65
65
import org .springframework .web .servlet .support .WebContentGenerator ;
66
+ import org .springframework .web .util .UriUtils ;
66
67
import org .springframework .web .util .UrlPathHelper ;
67
68
68
69
/**
@@ -727,21 +728,22 @@ else if (path.charAt(i) > ' ' && path.charAt(i) != 127) {
727
728
728
729
private static String normalizePath (String path ) {
729
730
String result = path ;
731
+ result = decode (result );
730
732
if (result .contains ("%" )) {
731
733
result = decode (result );
732
- if ( result . contains ( "%" )) {
733
- result = decode ( result );
734
- }
735
- if ( result . contains ( "../" )) {
736
- return StringUtils . cleanPath (result );
737
- }
734
+ }
735
+ if (! StringUtils . hasText ( result )) {
736
+ return result ;
737
+ }
738
+ if (result . contains ( "../" )) {
739
+ return StringUtils . cleanPath ( result );
738
740
}
739
741
return path ;
740
742
}
741
743
742
744
private static String decode (String path ) {
743
745
try {
744
- return URLDecoder .decode (path , StandardCharsets .UTF_8 );
746
+ return UriUtils .decode (path , StandardCharsets .UTF_8 );
745
747
}
746
748
catch (Exception ex ) {
747
749
return "" ;
You can’t perform that action at this time.
0 commit comments