Skip to content

Commit 71e2d8e

Browse files
committed
Handle correctly * in CorsConfiguration#combine() other parameter
Issue: SPR-13674
1 parent e8a0ef0 commit 71e2d8e

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.web.cors;
1818

1919
import java.util.ArrayList;
20-
import java.util.Arrays;
2120
import java.util.Collections;
2221
import java.util.List;
2322

@@ -103,7 +102,7 @@ public CorsConfiguration combine(CorsConfiguration other) {
103102
}
104103

105104
private List<String> combine(List<String> source, List<String> other) {
106-
if (other == null) {
105+
if (other == null || other.contains(ALL)) {
107106
return source;
108107
}
109108
if (source == null || source.contains(ALL)) {

spring-web/src/test/java/org/springframework/web/cors/CorsConfigurationTests.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,16 @@ public void combineWithAsteriskWildCard() {
114114
other.addAllowedHeader("header1");
115115
other.addExposedHeader("header2");
116116
other.addAllowedMethod(HttpMethod.PUT.name());
117-
config = config.combine(other);
118-
assertEquals(Arrays.asList("http://domain.com"), config.getAllowedOrigins());
119-
assertEquals(Arrays.asList("header1"), config.getAllowedHeaders());
120-
assertEquals(Arrays.asList("header2"), config.getExposedHeaders());
121-
assertEquals(Arrays.asList(HttpMethod.PUT.name()), config.getAllowedMethods());
117+
CorsConfiguration combinedConfig = config.combine(other);
118+
assertEquals(Arrays.asList("http://domain.com"), combinedConfig.getAllowedOrigins());
119+
assertEquals(Arrays.asList("header1"), combinedConfig.getAllowedHeaders());
120+
assertEquals(Arrays.asList("header2"), combinedConfig.getExposedHeaders());
121+
assertEquals(Arrays.asList(HttpMethod.PUT.name()), combinedConfig.getAllowedMethods());
122+
combinedConfig = other.combine(config);
123+
assertEquals(Arrays.asList("http://domain.com"), combinedConfig.getAllowedOrigins());
124+
assertEquals(Arrays.asList("header1"), combinedConfig.getAllowedHeaders());
125+
assertEquals(Arrays.asList("header2"), combinedConfig.getExposedHeaders());
126+
assertEquals(Arrays.asList(HttpMethod.PUT.name()), combinedConfig.getAllowedMethods());
122127
}
123128

124129
@Test

0 commit comments

Comments
 (0)