From 0cdc5369b73a97dd78b40b320182bb9b34849481 Mon Sep 17 00:00:00 2001 From: Khyojun Date: Fri, 4 Oct 2024 20:28:24 +0900 Subject: [PATCH] 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. --- .../org/springframework/web/cors/CorsConfiguration.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java b/spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java index 0ee455a69aed..ef195b00adfb 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java +++ b/spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java @@ -46,6 +46,7 @@ * @author Juergen Hoeller * @author Sam Brannen * @author Ruslan Akhundov + * @author khyojun * @since 4.2 * @see CORS spec */ @@ -54,9 +55,11 @@ public class CorsConfiguration { /** Wildcard representing all origins, methods, or headers. */ public static final String ALL = "*"; + private static final String PATH_SEPERATOR = "/"; + private static final List ALL_LIST = Collections.singletonList(ALL); - private static final OriginPattern ALL_PATTERN = new OriginPattern("*"); + private static final OriginPattern ALL_PATTERN = new OriginPattern(ALL); private static final List ALL_PATTERN_LIST = Collections.singletonList(ALL_PATTERN); @@ -157,7 +160,7 @@ public void setAllowedOrigins(@Nullable List origins) { } private String trimTrailingSlash(String origin) { - return (origin.endsWith("/") ? origin.substring(0, origin.length() - 1) : origin); + return (origin.endsWith(PATH_SEPERATOR) ? origin.substring(0, origin.length() - 1) : origin); } /**