Skip to content

Commit 74d69d0

Browse files
committedNov 27, 2024·
Merge branch '3.3.x'
Closes gh-43307
2 parents de26832 + 7bc709c commit 74d69d0

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed
 

‎spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -773,21 +773,21 @@ Elements append(Elements additional) {
773773
ElementType[] type = new ElementType[size];
774774
System.arraycopy(this.type, 0, type, 0, this.size);
775775
System.arraycopy(additional.type, 0, type, this.size, additional.size);
776-
CharSequence[] resolved = newResolved(size);
776+
CharSequence[] resolved = newResolved(0, size);
777777
for (int i = 0; i < additional.size; i++) {
778778
resolved[this.size + i] = additional.get(i);
779779
}
780780
return new Elements(this.source, size, this.start, this.end, type, resolved);
781781
}
782782

783783
Elements chop(int size) {
784-
CharSequence[] resolved = newResolved(size);
784+
CharSequence[] resolved = newResolved(0, size);
785785
return new Elements(this.source, size, this.start, this.end, this.type, resolved);
786786
}
787787

788788
Elements subElements(int offset) {
789789
int size = this.size - offset;
790-
CharSequence[] resolved = newResolved(size);
790+
CharSequence[] resolved = newResolved(offset, size);
791791
int[] start = new int[size];
792792
System.arraycopy(this.start, offset, start, 0, size);
793793
int[] end = new int[size];
@@ -797,10 +797,10 @@ Elements subElements(int offset) {
797797
return new Elements(this.source, size, start, end, type, resolved);
798798
}
799799

800-
private CharSequence[] newResolved(int size) {
800+
private CharSequence[] newResolved(int offset, int size) {
801801
CharSequence[] resolved = new CharSequence[size];
802802
if (this.resolved != null) {
803-
System.arraycopy(this.resolved, 0, resolved, 0, Math.min(size, this.size));
803+
System.arraycopy(this.resolved, offset, resolved, 0, Math.min(size, this.size));
804804
}
805805
return resolved;
806806
}

‎spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.Collections;
2121
import java.util.List;
22+
import java.util.Locale;
2223

2324
import org.junit.jupiter.api.Test;
2425

@@ -492,6 +493,21 @@ void subNameWhenOffsetLessThanSizeShouldReturnSubName() {
492493
assertThat(name.subName(2)).hasToString("baz");
493494
}
494495

496+
@Test
497+
void subNameOfAdaptedNameWhenOffsetLessThanSizeShouldReturnSubName() {
498+
ConfigurationPropertyName name = ConfigurationPropertyName.adapt("MY_LOGGING_LEVEL_ONE", '_');
499+
assertThat(name.subName(1)).hasToString("logging.level.one");
500+
assertThat(name.subName(2)).hasToString("level.one");
501+
}
502+
503+
@Test
504+
void subNameOfAdaptedNameWithValueProcessorWhenOffsetLessThanSizeShouldReturnSubName() {
505+
ConfigurationPropertyName name = ConfigurationPropertyName.adapt("MY_LOGGING_LEVEL_ONE", '_',
506+
(value) -> value.toString().toLowerCase(Locale.ENGLISH));
507+
assertThat(name.subName(1)).hasToString("logging.level.one");
508+
assertThat(name.subName(2)).hasToString("level.one");
509+
}
510+
495511
@Test
496512
void subNameWhenOffsetZeroShouldReturnName() {
497513
ConfigurationPropertyName name = ConfigurationPropertyName.of("foo.bar.baz");

0 commit comments

Comments
 (0)
Please sign in to comment.