You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "allthingssecurity (via GitHub)" <gi...@apache.org> on 2026/10/08 00:06:16 UTC

[PR] CAMEL-25353: camel-sql - expand each :#in: parameter where it is, also when its name starts another name [camel]

allthingssecurity opened a new pull request, #27528:
URL: https://github.com/apache/camel/pull/27528

   # Description
   
   [CAMEL-25353](https://issues.apache.org/jira/browse/CAMEL-25353)
   
   `DefaultSqlPrepareStatementStrategy.prepareQuery` found each `:?in:<name>` and then replaced every match of the regular expression `":?in:" + name` in the whole query. With `:#in:project` before `:#in:projectLicense`, the first replacement also replaced the start of the second parameter, which became `in (?,?License)` (a syntax error); and `:#in:${body[names]}` was not replaced at all, since `[` and `]` were not escaped.
   
   This change replaces each match where it is, in one pass (`Matcher.appendReplacement`), with as many placeholders as its own parameter has values. Queries that worked are prepared as before (also a name used more than once, which was replaced everywhere by its first match and is now replaced at each match with the same values), so there is no upgrade-guide note. It also no longer compiles a regular expression per `:#in:` parameter on each exchange.
   
   Tests: new `SqlProducerInParameterNamesTest`, both tests fail without the change with a `BadSqlGrammarException` (H2 sees `license in (?,?License)` and `project in (?:$ body[names] )`). camel-sql: 301 tests pass except the 2 of `SqlFunctionDataSourceTest`, whose embedded MariaDB cannot start on my machine (missing `libpcre2`), unrelated to this change.
   
   Found with a Lean 4 model of the `replaceAll` loop and of the one-pass replacement: "each IN list has the number of values of its own parameter" fails on main whenever the first name is a prefix of the second, and the fix gives the same SQL as main exactly when it is not (checked exhaustively on a small domain of names and value counts).
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes.
     (I built and tested the affected module, including the formatter and import-sort plugins. I did not run the full root build.)
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used.
     This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer.
   
   _Claude Code on behalf of allthingssecurity_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25353: camel-sql - expand each :#in: parameter where it is, also when its name starts another name [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus merged PR #27528:
URL: https://github.com/apache/camel/pull/27528


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25353: camel-sql - expand each :#in: parameter where it is, also when its name starts another name [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #27528:
URL: https://github.com/apache/camel/pull/27528#discussion_r4215823854


##########
components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerInParameterNamesTest.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.sql;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Each :#in: parameter is expanded to the number of its own values, also when its name is the start of the name of a
+ * later :#in: parameter, or when it is an expression with characters that are special in a regular expression.
+ */
+class SqlProducerInParameterNamesTest extends CamelTestSupport {
+
+    EmbeddedDatabase db;
+
+    @Override
+    public void doPreSetup() throws Exception {
+        db = new EmbeddedDatabaseBuilder()
+                .setName(getClass().getSimpleName())
+                .setType(EmbeddedDatabaseType.H2)
+                .addScript("sql/createAndPopulateDatabase6.sql").build();
+    }
+
+    @Override
+    public void doPostTearDown() throws Exception {
+        if (db != null) {
+            db.shutdown();
+        }
+    }
+
+    @Test
+    void testNameIsStartOfLaterName() {
+        Map<String, Object> headers = Map.of("project", List.of("Camel", "AMQ"), "projectLicense", List.of("ASF", "XXX"));

Review Comment:
   Optional: with two values on both sides, the test would still pass if every IN list were expanded with the first parameter's count. Different sizes also prove that each list gets the count of its own parameter (Camel with ASF/XXX/YYY is 3 rows in `createAndPopulateDatabase6.sql`):
   
   ```suggestion
           Map<String, Object> headers = Map.of("project", List.of("Camel"), "projectLicense", List.of("ASF", "XXX", "YYY"));
   ```
   
   (and `assertEquals(3, rows.size());` on the line below).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25353: camel-sql - expand each :#in: parameter where it is, also when its name starts another name [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #27528:
URL: https://github.com/apache/camel/pull/27528#issuecomment-6053735157

   <!-- ci-tested-modules -->
   :test_tube: **CI tested the following changed modules:**
   
   - `components/camel-sql`
   
   ---
   
   <details><summary>:microscope: Scalpel shadow comparison — Scalpel: 11 of 700 tested, 27 compile-only — current: 11 all tested</summary>
   
   [Maveniverse Scalpel](https://github.com/maveniverse/scalpel) detected **11 affected modules** (current approach: 11).
   
   **Skip-tests mode would test 11 modules** (1 direct + 10 downstream), **skip tests for 27** (generated code, meta-modules)
   
   <details><summary>Modules Scalpel would test (11)</summary>
   
   - `camel-jbang-mcp` ← downstream of org.apache.camel:camel-yaml-dsl
   - `camel-jbang-plugin-mcp` ← downstream of org.apache.camel:camel-jbang-core
   - `camel-jbang-plugin-route-parser` ← downstream of org.apache.camel:camel-route-parser
   - `camel-jbang-plugin-tui` ← downstream of org.apache.camel:camel-catalog
   - `camel-jbang-plugin-validate` ← downstream of org.apache.camel:camel-yaml-dsl-validator
   - `camel-jta` ← downstream of org.apache.camel:camel-sql
   - `camel-kafka` ← downstream of org.apache.camel:camel-sql
   - `camel-launcher-container` ← downstream of org.apache.camel:camel-launcher
   - `camel-sql` ← components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlPrepareStatementStrategy.java, components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerInParameterNamesTest.java
   - `camel-yaml-dsl-validator` ← downstream of org.apache.camel:camel-yaml-dsl
   - `camel-yaml-dsl-validator-maven-plugin` ← downstream of org.apache.camel:camel-yaml-dsl-validator
   
   </details>
   
   <details><summary>Modules with tests skipped (27)</summary>
   
   - `apache-camel`
   - `camel-allcomponents`
   - `camel-catalog`
   - `camel-catalog-console`
   - `camel-catalog-maven`
   - `camel-catalog-suggest`
   - `camel-componentdsl`
   - `camel-endpointdsl`
   - `camel-endpointdsl-support`
   - `camel-itest`
   - `camel-jbang-core`
   - `camel-jbang-it`
   - `camel-jbang-main`
   - `camel-jbang-plugin-edit`
   - `camel-jbang-plugin-generate`
   - `camel-jbang-plugin-kubernetes`
   - `camel-jbang-plugin-test`
   - `camel-kamelet-main`
   - `camel-launcher`
   - `camel-report-maven-plugin`
   - `camel-route-parser`
   - `camel-yaml-dsl`
   - `camel-yaml-dsl-deserializers`
   - `camel-yaml-dsl-maven-plugin`
   - `coverage`
   - `docs`
   - `dummy-component`
   
   </details>
   
   > :information_source: Shadow mode — Scalpel observes but does not affect test execution. [Learn more](https://github.com/maveniverse/scalpel)
   
   </details>
   
   <details><summary>All tested modules (38 modules, 6m 59s total)</summary>
   
   **Total reactor time:** 6m 59s
   
   | Module | Duration | Status |
   | --- | --- | --- |
   | Camel :: Launcher | 53.7s | SUCCESS |
   | Camel :: SQL | 52.2s | SUCCESS |
   | Camel :: JBang :: Plugin :: TUI | 44.2s | SUCCESS |
   | Camel :: JBang :: MCP | 40.6s | SUCCESS |
   | Camel :: Component DSL | 30.6s | SUCCESS |
   | Camel :: Catalog :: Camel Catalog | 23.2s | SUCCESS |
   | Camel :: YAML DSL :: Validator | 17.9s | SUCCESS |
   | Camel :: YAML DSL | 17.3s | SUCCESS |
   | Camel :: JBang :: Plugin :: Validate | 16.1s | SUCCESS |
   | Camel :: Docs | 14.7s | SUCCESS |
   | Camel :: JBang :: Plugin :: Testing | 14.2s | SUCCESS |
   | Camel :: JTA | 14.2s | SUCCESS |
   | Camel :: JBang :: Plugin :: Kubernetes | 10.6s | SUCCESS |
   | Camel :: Kamelet Main | 9.8s | SUCCESS |
   | Camel :: Catalog :: Camel Route Parser | 9.0s | SUCCESS |
   | Camel :: Catalog :: Camel Report Maven Plugin | 8.1s | SUCCESS |
   | Camel :: YAML DSL :: Deserializers | 7.8s | SUCCESS |
   | Camel :: YAML DSL :: Validator Maven Plugin | 5.3s | SUCCESS |
   | Camel :: All Components Sync point | 5.0s | SUCCESS |
   | Camel :: YAML DSL :: Maven Plugins | 3.7s | SUCCESS |
   | Camel :: Catalog :: Maven | 3.0s | SUCCESS |
   | Camel :: Catalog :: Suggest (deprecated) | 2.6s | SUCCESS |
   | Camel :: Catalog :: Dummy Component | 2.0s | SUCCESS |
   | Camel :: Assembly | 1.9s | SUCCESS |
   | Camel :: JBang :: Plugin :: Edit | 1.7s | SUCCESS |
   | Camel :: Coverage | 1.6s | SUCCESS |
   | Camel :: JBang :: Integration tests | 1.2s | SUCCESS |
   | Camel :: Endpoint DSL :: Support | 1.2s | SUCCESS |
   | Camel :: JBang :: Plugin :: Generate | 1.1s | SUCCESS |
   | Camel :: JBang :: Main | 1.0s | SUCCESS |
   | Camel :: Catalog :: Console | 0.9s | SUCCESS |
   | Camel :: JBang :: Plugin :: MCP | 0.9s | SUCCESS |
   | Camel :: JBang :: Plugin :: Route Parser | 0.8s | SUCCESS |
   | Camel :: Launcher :: Container | 0.7s | SUCCESS |
   | Camel :: Endpoint DSL | n/a |  |
   | Camel :: Integration Tests | n/a |  |
   | Camel :: JBang :: Core | n/a |  |
   | Camel :: Kafka | n/a |  |
   
   **Top 20 slowest modules:**
   - `Camel :: Launcher` (53.7s)
   - `Camel :: SQL` (52.2s)
   - `Camel :: JBang :: Plugin :: TUI` (44.2s)
   - `Camel :: JBang :: MCP` (40.6s)
   - `Camel :: Component DSL` (30.6s)
   - `Camel :: Catalog :: Camel Catalog` (23.2s)
   - `Camel :: YAML DSL :: Validator` (17.9s)
   - `Camel :: YAML DSL` (17.3s)
   - `Camel :: JBang :: Plugin :: Validate` (16.1s)
   - `Camel :: Docs` (14.7s)
   - `Camel :: JBang :: Plugin :: Testing` (14.2s)
   - `Camel :: JTA` (14.2s)
   - `Camel :: JBang :: Plugin :: Kubernetes` (10.6s)
   - `Camel :: Kamelet Main` (9.8s)
   - `Camel :: Catalog :: Camel Route Parser` (9.0s)
   - `Camel :: Catalog :: Camel Report Maven Plugin` (8.1s)
   - `Camel :: YAML DSL :: Deserializers` (7.8s)
   - `Camel :: YAML DSL :: Validator Maven Plugin` (5.3s)
   - `Camel :: All Components Sync point` (5.0s)
   - `Camel :: YAML DSL :: Maven Plugins` (3.7s)
   
   </details>
   
   ---
   :gear: [View full build and test results](https://github.com/apache/camel/actions/runs/37705945986)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25353: camel-sql - expand each :#in: parameter where it is, also when its name starts another name [camel]

Posted by "allthingssecurity (via GitHub)" <gi...@apache.org>.
allthingssecurity commented on code in PR #27528:
URL: https://github.com/apache/camel/pull/27528#discussion_r4216003397


##########
components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerInParameterNamesTest.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.sql;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Each :#in: parameter is expanded to the number of its own values, also when its name is the start of the name of a
+ * later :#in: parameter, or when it is an expression with characters that are special in a regular expression.
+ */
+class SqlProducerInParameterNamesTest extends CamelTestSupport {
+
+    EmbeddedDatabase db;
+
+    @Override
+    public void doPreSetup() throws Exception {
+        db = new EmbeddedDatabaseBuilder()
+                .setName(getClass().getSimpleName())
+                .setType(EmbeddedDatabaseType.H2)
+                .addScript("sql/createAndPopulateDatabase6.sql").build();
+    }
+
+    @Override
+    public void doPostTearDown() throws Exception {
+        if (db != null) {
+            db.shutdown();
+        }
+    }
+
+    @Test
+    void testNameIsStartOfLaterName() {
+        Map<String, Object> headers = Map.of("project", List.of("Camel", "AMQ"), "projectLicense", List.of("ASF", "XXX"));

Review Comment:
   Applied in ba88035a1f61: `project` has one value and `projectLicense` three, and the test expects 3 rows (Camel with ASF/XXX/YYY in `createAndPopulateDatabase6.sql`). It passes with the change; without it H2 still fails on `license in (?License)`.
   
   _Claude Code on behalf of allthingssecurity_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25353: camel-sql - expand each :#in: parameter where it is, also when its name starts another name [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #27528:
URL: https://github.com/apache/camel/pull/27528#issuecomment-6053222623

   :star2: Thank you for your contribution to the Apache Camel project! :star2:
     :robot: CI automation will test this PR automatically.
   
     :camel: Apache Camel Committers, please review the following items:
   
     * First-time contributors **require MANUAL approval** for the GitHub Actions to run
     * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
     * You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
     * Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
     
     :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org