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 cbbf31cce4c8 CAMEL-27111: optional placeholder removal must not 
URL-encode other parameters (#30283)
cbbf31cce4c8 is described below

commit cbbf31cce4c81ae76f4806254bd1ef7ffb7b7d60
Author: Guillaume Nodet <[email protected]>
AuthorDate: Tue Nov 17 21:07:11 2026 +0100

    CAMEL-27111: optional placeholder removal must not URL-encode other 
parameters (#30283)
    
    When an optional property placeholder ({{?name}}) is unresolved,
    doResolveEndpointUriOptionalPropertyPlaceholders() rebuilt the query
    string via URISupport.parseQuery(query) followed by
    URISupport.createQueryString(keep).
    
    parseQuery() URL-decodes values, while createQueryString() URL-encodes
    them. For values that contain URL-special characters (colons, slashes,
    question marks, equals signs) -- e.g. a URL passed as a Kamelet
    parameter -- the decode-then-reencode round-trip corrupts the value
    (e.g. http://host/path?q=v becomes http%3A%2F%2Fhost%2Fpath%3Fq%3Dv).
    
    Fix: use parseQuery(query, true) (raw mode, no decoding) together with
    createQueryString(keep, false) (no re-encoding) so the original raw
    query values are preserved as-is.
    
    Tests: PropertiesComponentIgnoreMissingPropertyTest covers the main case,
    the optional placeholder before the other parameters, an already encoded
    value and a RAW value; KameletOptionalParameterTest covers a Kamelet whose
    url parameter is an endpoint URI with its own query. All fail without the
    fix.
    
    Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet.
    
    Co-authored-by: Claude Sonnet 4.6 <[email protected]>
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../kamelet/KameletOptionalParameterTest.java      | 54 ++++++++++++++++++++++
 ...opertiesComponentIgnoreMissingPropertyTest.java | 20 ++++++++
 .../org/apache/camel/support/EndpointHelper.java   | 10 ++--
 3 files changed, 81 insertions(+), 3 deletions(-)

diff --git 
a/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletOptionalParameterTest.java
 
b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletOptionalParameterTest.java
new file mode 100644
index 000000000000..524c07b38ede
--- /dev/null
+++ 
b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletOptionalParameterTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.kamelet;
+
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+/**
+ * CAMEL-27111: an unresolved optional placeholder on a Kamelet URI must not 
URL-encode the other parameters.
+ */
+class KameletOptionalParameterTest extends CamelTestSupport {
+
+    @Test
+    void testUnresolvedOptionalParameter() throws Exception {
+        
getMockEndpoint("mock:result?retainFirst=5").expectedBodiesReceived("Hello 
World");
+
+        template.sendBody("direct:start", "Hello World");
+
+        MockEndpoint.assertIsSatisfied(context);
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                routeTemplate("mysink")
+                        .templateParameter("url")
+                        .from("kamelet:source")
+                        .to("{{url}}");
+
+                from("direct:start")
+                        
.to("kamelet:mysink?url=mock:result?retainFirst=5&foo={{?nosuchproperty}}");
+            }
+        };
+    }
+}
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentIgnoreMissingPropertyTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentIgnoreMissingPropertyTest.java
index 17db859228ab..325df0bdc852 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentIgnoreMissingPropertyTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentIgnoreMissingPropertyTest.java
@@ -48,6 +48,26 @@ public class PropertiesComponentIgnoreMissingPropertyTest 
extends ContextTestSup
         Assertions.assertEquals("foo:dummy?a=1&b={{foo}}&c=10", out);
     }
 
+    @Test
+    public void testOptionalPlaceholderDoesNotUrlEncodeOtherParams() {
+        // CAMEL-27111: when an optional placeholder is unset, the remaining 
parameters
+        // must not be URL-encoded. Values containing URL-special characters 
(colons, slashes,
+        // question marks, equals signs) must survive the optional-placeholder 
removal unchanged.
+        String out = 
EndpointHelper.resolveEndpointUriPropertyPlaceholders(context,
+                
"kamelet:http-sink?url=http://127.0.0.1:18089/open/with?q=status_s:new&foo={{?nosuchproperty}}";);
+        
Assertions.assertEquals("kamelet:http-sink?url=http://127.0.0.1:18089/open/with?q=status_s:new";,
 out);
+
+        // the optional placeholder before the other parameters
+        out = EndpointHelper.resolveEndpointUriPropertyPlaceholders(context,
+                
"kamelet:http-sink?foo={{?nosuchproperty}}&url=http://127.0.0.1:18089/open/with?q=status_s:new";);
+        
Assertions.assertEquals("kamelet:http-sink?url=http://127.0.0.1:18089/open/with?q=status_s:new";,
 out);
+
+        // an already encoded value, and a RAW value, are kept as they are
+        out = EndpointHelper.resolveEndpointUriPropertyPlaceholders(context,
+                
"mock:result?a=hello%20world&foo={{?nosuchproperty}}&b=RAW(se+cr&t)");
+        Assertions.assertEquals("mock:result?a=hello%20world&b=RAW(se+cr&t)", 
out);
+    }
+
     @Override
     protected CamelContext createCamelContext() throws Exception {
         CamelContext context = super.createCamelContext();
diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java 
b/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
index afda66391516..756a54311fad 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
@@ -141,10 +141,14 @@ public final class EndpointHelper {
 
         // the query parameters needs to be rebuild by removing the unresolved 
key=value pairs
         if (query != null && query.contains(prefix)) {
-            Map<String, Object> params = URISupport.parseQuery(query);
+            // use raw mode to avoid URL-decoding parameter values (which 
would corrupt values
+            // containing special characters such as colons, slashes, question 
marks or equals signs,
+            // e.g. a URL passed as a Kamelet parameter). The corresponding 
createQueryString call
+            // must skip re-encoding to preserve the original raw values as-is.
+            Map<String, Object> params = URISupport.parseQuery(query, true);
             final Map<String, Object> keep = extractParamsToKeep(params, 
prefix);
-            // rebuild query
-            query = URISupport.createQueryString(keep);
+            // rebuild query without re-encoding (values are already raw)
+            query = URISupport.createQueryString(keep, false);
         }
 
         // assemble uri as answer

Reply via email to