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 f52c453b978b CAMEL-26388: camel-util -
URISupport.textBlockToSingleLine: fast path for a uri without line breaks
(#28647)
f52c453b978b is described below
commit f52c453b978bef151b30c7ae3d38267a9856eb9c
Author: Adriano Machado <[email protected]>
AuthorDate: Thu Oct 29 01:38:31 2026 -0400
CAMEL-26388: camel-util - URISupport.textBlockToSingleLine: fast path for a
uri without line breaks (#28647)
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../java/org/apache/camel/util/URISupport.java | 4 ++++
.../java/org/apache/camel/util/URISupportTest.java | 26 ++++++++++++++++++++++
2 files changed, 30 insertions(+)
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 21e86cb35ddb..411cdd581286 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
@@ -210,6 +210,10 @@ public final class URISupport {
public static String textBlockToSingleLine(String uri) {
// Java 17 text blocks have new lines with optional white space
if (uri != null) {
+ if (uri.indexOf('\n') == -1 && uri.indexOf('\r') == -1) {
+ // a single line gives the same result as below, and this is
called for every getEndpoint(String)
+ return uri.trim();
+ }
// we want text blocks to be as-is before query parameters
// as this allows some Camel components to provide code or SQL
// to be provided in the context-path.
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 44a0b98b27ef..3efd2c663858 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
@@ -990,4 +990,30 @@ public class URISupportTest {
assertThat(URISupport.sanitizePath("joe:pa/ss@host/dir")).isEqualTo("joe:xxxxxx@host/dir");
}
+ @Test
+ public void testTextBlockToSingleLine() {
+ assertThat(URISupport.textBlockToSingleLine(null)).isNull();
+ assertThat(URISupport.textBlockToSingleLine("")).isEmpty();
+ // the context-path is kept as-is before the query, and the query
lines are trimmed
+ assertThat(URISupport.textBlockToSingleLine("""
+ sql:select *
+ from orders?
+ dataSource=#ds&
+ useIterator=false
+ """)).isEqualTo("sql:select * from
orders?dataSource=#ds&useIterator=false");
+ assertThat(URISupport.textBlockToSingleLine("sql:select *\r\nfrom
orders\r\n"))
+ .isEqualTo("sql:select * from orders");
+ }
+
+ @Test
+ public void testTextBlockToSingleLineWithoutLineBreak() {
+ // a uri on a single line is only trimmed, white space inside it is
kept
+ assertThat(URISupport.textBlockToSingleLine(" sql:select * from
t?x=1 "))
+ .isEqualTo("sql:select * from t?x=1");
+ assertThat(URISupport.textBlockToSingleLine(" \t ")).isEmpty();
+ // getEndpoint(String) calls this for every uri, so a uri that needs
no change must not be copied
+ String uri = "direct:foo?bar=1";
+ assertThat(URISupport.textBlockToSingleLine(uri)).isSameAs(uri);
+ }
+
}