This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch backport/23797-to-camel-4.18.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit 07e61d5a491dc722f712337e4bd4454a55c06613 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 beaec95280f8..05610ddb1520 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");
