-
Notifications
You must be signed in to change notification settings - Fork 5.1k
CAMEL-23594: Fix property resolution issues in kamelet endpoint URIs #23391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,8 @@ | |||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| package org.apache.camel.component.kamelet; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import java.net.URLDecoder; | ||||||||||||||||||||||||||
| import java.nio.charset.StandardCharsets; | ||||||||||||||||||||||||||
| import java.util.ArrayList; | ||||||||||||||||||||||||||
| import java.util.Collections; | ||||||||||||||||||||||||||
| import java.util.HashMap; | ||||||||||||||||||||||||||
|
|
@@ -132,6 +134,18 @@ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Obje | |||||||||||||||||||||||||
| parameters.remove(PARAM_LOCATION); | ||||||||||||||||||||||||||
| parameters.remove(PARAM_UUID); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // URL-decode non-RAW parameter values. The YAML DSL URL-encodes property values | ||||||||||||||||||||||||||
| // when building query strings (via URISupport.createQueryString), but useRawUri=true | ||||||||||||||||||||||||||
| // prevents automatic decoding during URI parsing. Decode here so values like | ||||||||||||||||||||||||||
| // "application/json" are not left as "application%2Fjson". | ||||||||||||||||||||||||||
| for (Map.Entry<String, Object> entry : parameters.entrySet()) { | ||||||||||||||||||||||||||
| if (entry.getValue() instanceof String s | ||||||||||||||||||||||||||
| && !s.startsWith(URISupport.RAW_TOKEN_PREFIX + "(") | ||||||||||||||||||||||||||
| && !s.startsWith(URISupport.RAW_TOKEN_PREFIX + "{")) { | ||||||||||||||||||||||||||
| entry.setValue(URLDecoder.decode(s, StandardCharsets.UTF_8)); | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Consider either:
Suggested change
Though option 1 (fixing the encoding at the YAML DSL source) would be the cleanest solution. Claude Code on behalf of Guillaume Nodet |
||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // manually need to resolve raw parameters as input to the kamelet because | ||||||||||||||||||||||||||
| // resolveRawParameterValues is false | ||||||||||||||||||||||||||
| // this ensures that parameters such as passwords are used as-is and not encoded | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -514,7 +514,7 @@ private String doGetPropertyValue(String key, String defaultValue) { | |
| if (answer == null) { | ||
| answer = value; | ||
| } | ||
| return answer; | ||
| return answer != null ? answer.trim() : null; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This The root cause is YAML literal block scalars ( Consider removing this change and instead trimming at the YAML DSL level where property values are extracted from block scalars.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This The root cause is YAML literal block scalars ( Suggest removing this change entirely. Claude Code on behalf of Guillaume Nodet |
||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createEndpoint()is called from all DSLs (Java, XML, YAML), not just YAML. If a value arrives without URL-encoding (e.g., from Java DSLto("kamelet:foo?contentType=application/json")),URLDecoder.decode()will still process it. Whileapplication/jsonsurvives decoding, a value containing%(like100%done) would be corrupted or throw anIllegalArgumentException.Consider either:
URISupport.createQueryString()call) so values aren't double-encoded%xxpatterns)