Skip to content

Commit 0cdc536

Browse files
committed
Refactor : Replace hardcoded PATH_SEPERATOR & ALL mark in ALL_PATERN
- The * symbol was already handled as a constant, but the / symbol was not. Handling this as a constant will improve readability. - Additionally, the * symbol was replaced in other parts of the code, but it was not replaced in OriginPattern, which caused some confusion. It seems necessary to replace it there as well.
1 parent beca562 commit 0cdc536

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
* @author Juergen Hoeller
4747
* @author Sam Brannen
4848
* @author Ruslan Akhundov
49+
* @author khyojun
4950
* @since 4.2
5051
* @see <a href="https://www.w3.org/TR/cors/">CORS spec</a>
5152
*/
@@ -54,9 +55,11 @@ public class CorsConfiguration {
5455
/** Wildcard representing <em>all</em> origins, methods, or headers. */
5556
public static final String ALL = "*";
5657

58+
private static final String PATH_SEPERATOR = "/";
59+
5760
private static final List<String> ALL_LIST = Collections.singletonList(ALL);
5861

59-
private static final OriginPattern ALL_PATTERN = new OriginPattern("*");
62+
private static final OriginPattern ALL_PATTERN = new OriginPattern(ALL);
6063

6164
private static final List<OriginPattern> ALL_PATTERN_LIST = Collections.singletonList(ALL_PATTERN);
6265

@@ -157,7 +160,7 @@ public void setAllowedOrigins(@Nullable List<String> origins) {
157160
}
158161

159162
private String trimTrailingSlash(String origin) {
160-
return (origin.endsWith("/") ? origin.substring(0, origin.length() - 1) : origin);
163+
return (origin.endsWith(PATH_SEPERATOR) ? origin.substring(0, origin.length() - 1) : origin);
161164
}
162165

163166
/**

0 commit comments

Comments
 (0)