Checking for invalid characters in SpringBootContextLoader.setActiveProfiles

pull/36262/head
Bernardo Bulgarelli 1 year ago
parent a8e9132500
commit d12274a2da

@ -236,7 +236,7 @@ public class SpringBootContextLoader extends AbstractContextLoader implements Ao
}
private boolean containsProhibitedCharacters(String str){
String regex = ".*[*&!|].*";
String regex = ".*[*&!|,].*";
return str.matches(regex);
}
@ -247,7 +247,7 @@ public class SpringBootContextLoader extends AbstractContextLoader implements Ao
}
for (String profile : profiles) {
if (containsProhibitedCharacters(profile)) {
throw new IllegalArgumentException("Invalid profile: '" + profile + "'. Profile names can't contain '*', '&', '!' or '|'.");
throw new IllegalArgumentException("Invalid profile: '" + profile + "'. Profile names can't contain '*', '&', '!', ',' or '|'.");
}
}
if (!applicationEnvironment) {

@ -127,7 +127,9 @@ class SpringBootContextLoaderTests {
@Test
void activeProfileWithComma() {
assertThat(getActiveProfiles(ActiveProfileWithComma.class)).containsExactly("profile1,2");
Assertions.assertThrows(Exception.class, () ->
assertThat(getActiveProfiles(ActiveProfileWithComma.class)).containsExactly("profile1,2")
);
}
@Test
@ -364,7 +366,7 @@ class SpringBootContextLoaderTests {
}
@SpringBootTest(properties = { "key=myValue" }, classes = Config.class)
@ActiveProfiles({ "profile1,2" })
@ActiveProfiles({ "profile1" })
static class ActiveProfileWithInlinedProperties {
}

Loading…
Cancel
Save