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 5a6533286985 CAMEL-23698: camel-util - Do not append trailing ? to URI 
when query string is empty (#23797)
5a6533286985 is described below

commit 5a6533286985401c37526b743add8ff5debbf7fa
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Jun 5 23:01:31 2026 +0200

    CAMEL-23698: camel-util - Do not append trailing ? to URI when query string 
is empty (#23797)
    
    Signed-off-by: Claus Ibsen <[email protected]>
    Co-authored-by: Claude <[email protected]>
---
 .../src/main/java/org/apache/camel/util/URISupport.java           | 2 +-
 .../src/test/java/org/apache/camel/util/URISupportTest.java       | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git 
a/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java 
b/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
index 84127b3a501f..8ab513173e17 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
@@ -443,7 +443,7 @@ public final class URISupport {
         if (before != null) {
             s = before;
         }
-        if (query != null) {
+        if (query != null && !query.isEmpty()) {
             s = s + "?" + query;
         }
         if (!s.contains("#") && uri.getFragment() != null) {
diff --git 
a/core/camel-util/src/test/java/org/apache/camel/util/URISupportTest.java 
b/core/camel-util/src/test/java/org/apache/camel/util/URISupportTest.java
index b1e6d73c6295..48f908ba55d8 100644
--- a/core/camel-util/src/test/java/org/apache/camel/util/URISupportTest.java
+++ b/core/camel-util/src/test/java/org/apache/camel/util/URISupportTest.java
@@ -185,6 +185,14 @@ public class URISupportTest {
         assertEquals("smtp://localhost?utm_campaign=launch#fragmentOne", 
resultUri.toString());
     }
 
+    @Test
+    public void testCreateURIWithQueryEmptyQueryString() throws Exception {
+        URI uri = new URI("https://api.example.com/users/myuser/repos";);
+        URI resultUri = URISupport.createURIWithQuery(uri, "");
+        assertNotNull(resultUri);
+        assertEquals("https://api.example.com/users/myuser/repos";, 
resultUri.toString());
+    }
+
     @Test
     public void testNormalizeEndpointWithEqualSignInParameter() throws 
Exception {
         String out = 
URISupport.normalizeUri("jms:queue:foo?selector=somekey='somevalue'&foo=bar");

Reply via email to