This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch fix/CAMEL-24047 in repository https://gitbox.apache.org/repos/asf/camel.git
commit b8aaf8acc0f297f49bdc3d6507e392a63eadbd92 Author: Claus Ibsen <[email protected]> AuthorDate: Wed Jul 15 10:57:57 2026 +0200 CAMEL-24047: camel-sql - verifyTableName accepts schema-qualified names Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../aggregate/jdbc/JdbcAggregationRepository.java | 3 +- ...bcAggregationRepositoryVerifyTableNameTest.java | 92 ++++++++++++++++++++++ .../ROOT/pages/camel-4x-upgrade-guide-4_22.adoc | 7 ++ 3 files changed, 101 insertions(+), 1 deletion(-) diff --git a/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepository.java b/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepository.java index 800ab575fba2..0593b7f71227 100644 --- a/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepository.java +++ b/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepository.java @@ -240,8 +240,9 @@ public class JdbcAggregationRepository extends ServiceSupport } // Useful to verify if the table name does not contain invalid characters. + // Allows simple names (my_table) and schema-qualified names (myschema.my_table). protected static void verifyTableName(String tableName) { - if (!tableName.matches("[a-zA-Z_][a-zA-Z0-9_]*")) { + if (!tableName.matches("[a-zA-Z_][a-zA-Z0-9_]*(\\.[a-zA-Z_][a-zA-Z0-9_]*)?")) { throw new IllegalArgumentException("Invalid repository name: " + tableName); } } diff --git a/components/camel-sql/src/test/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepositoryVerifyTableNameTest.java b/components/camel-sql/src/test/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepositoryVerifyTableNameTest.java new file mode 100644 index 000000000000..dece7bf0da90 --- /dev/null +++ b/components/camel-sql/src/test/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepositoryVerifyTableNameTest.java @@ -0,0 +1,92 @@ +/* + * 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.processor.aggregate.jdbc; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class JdbcAggregationRepositoryVerifyTableNameTest { + + @Test + public void testSimpleNameAccepted() { + assertDoesNotThrow(() -> JdbcAggregationRepository.verifyTableName("aggregation")); + } + + @Test + public void testSimpleNameWithUnderscoreAccepted() { + assertDoesNotThrow(() -> JdbcAggregationRepository.verifyTableName("camel_agg")); + } + + @Test + public void testNameStartingWithUnderscoreAccepted() { + assertDoesNotThrow(() -> JdbcAggregationRepository.verifyTableName("_my_table")); + } + + @Test + public void testSchemaQualifiedNameAccepted() { + assertDoesNotThrow(() -> JdbcAggregationRepository.verifyTableName("myschema.camel_agg")); + } + + @Test + public void testSchemaQualifiedCompletedNameAccepted() { + assertDoesNotThrow(() -> JdbcAggregationRepository.verifyTableName("myschema.camel_agg_completed")); + } + + @Test + public void testSqlInjectionRejected() { + assertThrows(IllegalArgumentException.class, + () -> JdbcAggregationRepository.verifyTableName("foo; DROP TABLE bar")); + } + + @Test + public void testEmptyNameRejected() { + assertThrows(IllegalArgumentException.class, + () -> JdbcAggregationRepository.verifyTableName("")); + } + + @Test + public void testNameStartingWithDigitRejected() { + assertThrows(IllegalArgumentException.class, + () -> JdbcAggregationRepository.verifyTableName("1table")); + } + + @Test + public void testDoubleDotRejected() { + assertThrows(IllegalArgumentException.class, + () -> JdbcAggregationRepository.verifyTableName("schema..table")); + } + + @Test + public void testTrailingDotRejected() { + assertThrows(IllegalArgumentException.class, + () -> JdbcAggregationRepository.verifyTableName("schema.")); + } + + @Test + public void testLeadingDotRejected() { + assertThrows(IllegalArgumentException.class, + () -> JdbcAggregationRepository.verifyTableName(".table")); + } + + @Test + public void testMultipleDotsRejected() { + assertThrows(IllegalArgumentException.class, + () -> JdbcAggregationRepository.verifyTableName("catalog.schema.table")); + } +} diff --git a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc index 859c222605bc..89ad3820e47f 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc @@ -436,3 +436,10 @@ The aggregation tables used with these repositories must have the `version BIGIN already required by `JdbcAggregationRepository` for reading and updating aggregates. When `recoveryByInstance` is enabled, the completed table must have the `instance_id VARCHAR(255)` column as documented. + +=== camel-sql - Schema-qualified aggregation repository names + +The table-name validation in `JdbcAggregationRepository` now accepts schema-qualified names +such as `myschema.aggregation`. Previously the validation regex only allowed simple identifiers +(`[a-zA-Z_][a-zA-Z0-9_]*`), rejecting any name containing a dot. Names starting with a digit, +containing spaces, or with multiple dots (e.g. `catalog.schema.table`) are still rejected.
