This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 89b8be7d97d0 CAMEL-26895: @BeanConfigInject binds sibling properties
outside the prefix (#29735)
89b8be7d97d0 is described below
commit 89b8be7d97d0e4c2a1f73aeee6a23a77dac4d7d3
Author: Sharang Gupta <[email protected]>
AuthorDate: Thu Nov 12 20:44:51 2026 +0000
CAMEL-26895: @BeanConfigInject binds sibling properties outside the prefix
(#29735)
getInjectionBeanConfigValue matched config properties with
startsWith(prefix) and no boundary, so a sibling key such as database.name
leaked into @BeanConfigInject("db"). Match the key itself or the prefix
followed by a dot. Regression test added to MainIoCBeanConfigInjectMapTest.
Prepared by Claude Code on behalf of Sharang Gupta.
Co-authored-by: Claude Opus 4.8 <[email protected]>
---
.../java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java | 5 +++--
.../java/org/apache/camel/main/MainIoCBeanConfigInjectMapTest.java | 3 +++
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java
index 22662075d233..955e052f48d1 100644
---
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java
+++
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java
@@ -490,8 +490,9 @@ public class CamelPostProcessorHelper implements
CamelContextAware {
}
for (String key : props.stringPropertyNames()) {
String uKey = key.toUpperCase(Locale.US);
- // need to ignore case
- if (uKey.startsWith(uRootKey)) {
+ // need to ignore case; match the key itself or the prefix up to a
'.' boundary so a
+ // sibling such as "database" is not captured for prefix "db"
+ if (uKey.equals(uRootKey) || uKey.startsWith(uRootKey + ".")) {
// strip prefix
String sKey = key.substring(rootKey.length());
if (sKey.startsWith(".")) {
diff --git
a/core/camel-main/src/test/java/org/apache/camel/main/MainIoCBeanConfigInjectMapTest.java
b/core/camel-main/src/test/java/org/apache/camel/main/MainIoCBeanConfigInjectMapTest.java
index 01f8ef8536e6..1aeb81c99c70 100644
---
a/core/camel-main/src/test/java/org/apache/camel/main/MainIoCBeanConfigInjectMapTest.java
+++
b/core/camel-main/src/test/java/org/apache/camel/main/MainIoCBeanConfigInjectMapTest.java
@@ -38,6 +38,8 @@ public class MainIoCBeanConfigInjectMapTest {
main.addInitialProperty("bar.Name", "Thirsty Bear");
main.addInitialProperty("Bar.AGE", "23");
main.addInitialProperty("foo", "blah");
+ // sibling key sharing the prefix but not on a '.' boundary must not
be captured
+ main.addInitialProperty("barstool", "leaked");
main.start();
CamelContext camelContext = main.getCamelContext();
@@ -73,6 +75,7 @@ public class MainIoCBeanConfigInjectMapTest {
public MyBar createBar(@BeanConfigInject("bar") Map config) {
assertEquals(2, config.size());
assertNull(config.get("foo"));
+ assertNull(config.get("stool"));
String text = config.get("Name") + " (minimum age: " +
config.get("AGE") + ")";
return new MyBar(text);