Skip to content

Commit

Permalink
fix: avoid out of range error with long profile names (#1272)
Browse files Browse the repository at this point in the history
* fix: avoid out of range error with long profile names
  • Loading branch information
jeloba authored Jan 2, 2025
1 parent 7d66a3a commit ab22555
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ public static String activeName(final String name, final List<String> profiles)
int toOffset = 1;
while (nextSplit != -1) {
for (String profile : profiles) {
char expectedEnd = name.charAt(toOffset + profile.length());
int end = toOffset + profile.length();
if (end >= name.length()) {
continue;
}
char expectedEnd = name.charAt(end);
if ((expectedEnd == '.' || expectedEnd == ',') &&
name.regionMatches(toOffset, profile, 0, profile.length())) {
return name.substring(profilesEnd + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,12 @@ void duplicatedProfilesActive() {
assertIterableEquals(List.of("kubernetes", "prod", "cluster"), config.getProfiles());
}

@Test
void profilesLongerThanPropDoNotOverflowString() {
String name = ProfileConfigSourceInterceptor.activeName("%a,b.c.d", List.of("test-with-native-agent"));
assertEquals("%a,b.c.d", name);
}

private static SmallRyeConfig buildConfig(String... keyValues) {
return new SmallRyeConfigBuilder()
.addDefaultInterceptors()
Expand Down

0 comments on commit ab22555

Please sign in to comment.