File tree Expand file tree Collapse file tree 2 files changed +32
-17
lines changed
spring-webflux/src/main/java/org/springframework/web/reactive/resource
spring-webmvc/src/main/java/org/springframework/web/servlet/resource Expand file tree Collapse file tree 2 files changed +32
-17
lines changed Original file line number Diff line number Diff line change @@ -98,22 +98,29 @@ else if (path.charAt(i) > ' ' && path.charAt(i) != 127) {
98
98
}
99
99
return (slash ? "/" : "" );
100
100
}
101
-
101
+
102
102
private static String normalizePath (String path ) {
103
- if (path .contains ("%" )) {
104
- try {
105
- path = URLDecoder .decode (path , StandardCharsets .UTF_8 );
106
- }
107
- catch (Exception ex ) {
108
- return "" ;
103
+ String result = path ;
104
+ if (result .contains ("%" )) {
105
+ result = decode (result );
106
+ if (result .contains ("%" )) {
107
+ result = decode (result );
109
108
}
110
- if (path .contains ("../" )) {
111
- path = StringUtils .cleanPath (path );
109
+ if (result .contains ("../" )) {
110
+ return StringUtils .cleanPath (result );
112
111
}
113
112
}
114
113
return path ;
115
114
}
116
115
116
+ private static String decode (String path ) {
117
+ try {
118
+ return URLDecoder .decode (path , StandardCharsets .UTF_8 );
119
+ }
120
+ catch (Exception ex ) {
121
+ return "" ;
122
+ }
123
+ }
117
124
118
125
/**
119
126
* Whether the given input path is invalid as determined by
Original file line number Diff line number Diff line change @@ -680,20 +680,28 @@ else if (path.charAt(i) > ' ' && path.charAt(i) != 127) {
680
680
}
681
681
682
682
private static String normalizePath (String path ) {
683
- if (path .contains ("%" )) {
684
- try {
685
- path = URLDecoder .decode (path , StandardCharsets .UTF_8 );
686
- }
687
- catch (Exception ex ) {
688
- return "" ;
683
+ String result = path ;
684
+ if (result .contains ("%" )) {
685
+ result = decode (result );
686
+ if (result .contains ("%" )) {
687
+ result = decode (result );
689
688
}
690
- if (path .contains ("../" )) {
691
- path = StringUtils .cleanPath (path );
689
+ if (result .contains ("../" )) {
690
+ return StringUtils .cleanPath (result );
692
691
}
693
692
}
694
693
return path ;
695
694
}
696
695
696
+ private static String decode (String path ) {
697
+ try {
698
+ return URLDecoder .decode (path , StandardCharsets .UTF_8 );
699
+ }
700
+ catch (Exception ex ) {
701
+ return "" ;
702
+ }
703
+ }
704
+
697
705
/**
698
706
* Invoked after {@link ResourceHandlerUtils#isInvalidPath(String)}
699
707
* to allow subclasses to perform further validation.
You can’t perform that action at this time.
0 commit comments