This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch CAMEL-27365-validate-regex-placeholder
in repository https://gitbox.apache.org/repos/asf/camel.git

commit ecf09f12e1d9732732297ed23027fb581fbabcc2
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 22 09:59:15 2026 +0100

    CAMEL-27365: camel-jbang - camel validate no longer reports an include or 
exclude with a property placeholder, such as RAW({{?include}}), as an invalid 
regular expression
    
    The check of the include and exclude options of the file components
    skipped a value that starts with {{, but not one in RAW(), as the
    sftp-source Kamelet has: RAW({{?include}}) was compiled as a regex and
    reported. A value with a property placeholder anywhere is now skipped,
    as it is only known at runtime, and the value inside RAW(...) or
    RAW{...} is what is checked, as RAW is not part of the regex.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../dsl/jbang/core/commands/ai/EndpointChecks.java | 17 ++++++++++--
 .../commands/ai/SourceValidatorEndpointTest.java   | 30 ++++++++++++++++++++++
 2 files changed, 45 insertions(+), 2 deletions(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/EndpointChecks.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/EndpointChecks.java
index 44bac54ce083..33c1e2b35d46 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/EndpointChecks.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/EndpointChecks.java
@@ -596,8 +596,10 @@ final class EndpointChecks {
                 continue;
             }
             String name = pair.substring(0, eq);
-            String value = pair.substring(eq + 1);
-            if (!name.equals("include") && !name.equals("exclude") || 
value.startsWith("{{")) {
+            String value = withoutRaw(pair.substring(eq + 1));
+            if (!name.equals("include") && !name.equals("exclude") || 
value.contains("{{")) {
+                // a value with a property placeholder, such as 
RAW({{?include}}) in a Kamelet, is only known at
+                // runtime, and {{ is no regex (CAMEL-27365)
                 continue;
             }
             String unquoted = withoutQuoteCharacters(value);
@@ -632,6 +634,17 @@ final class EndpointChecks {
         }
     }
 
+    /**
+     * The value inside RAW(...) or RAW{...}, which is not part of the value; 
the value itself when it is not in RAW.
+     */
+    static String withoutRaw(String value) {
+        if (value.length() > 5 && (value.startsWith("RAW(") && 
value.endsWith(")")
+                || value.startsWith("RAW{") && value.endsWith("}"))) {
+            return value.substring(4, value.length() - 1);
+        }
+        return value;
+    }
+
     /**
      * The value without the quote characters (" or ', with or without a 
backslash before them) at its ends, which a
      * regex of a file name never has there; the value itself when it has none.
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/SourceValidatorEndpointTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/SourceValidatorEndpointTest.java
index 178c299a7f9f..fe84168210bf 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/SourceValidatorEndpointTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/SourceValidatorEndpointTest.java
@@ -524,6 +524,36 @@ class SourceValidatorEndpointTest {
                 .contains("write 
include=.*\\.txt").contains("antInclude=*.txt");
     }
 
+    @Test
+    void aPlaceholderInTheFileIncludeOptionIsNotCheckedAsARegex() {
+        // CAMEL-27365: the sftp-source Kamelet has include: 
"RAW({{?include}})", the value is only known at runtime
+        List<String> msgs = SourceValidator.validateYamlEndpoints("""
+                - from:
+                    uri: sftp:{{host}}:22/{{directory}}
+                    parameters:
+                      username: admin
+                      include: "RAW({{?include}})"
+                      exclude: "RAW({{?exclude}})"
+                    steps:
+                      - log: "${body}"
+                - from:
+                    uri: 
file:input?include={{prefix}}*&exclude=RAW({{?exclude}})&noop=true
+                    steps:
+                      - log: "${body}"
+                """, catalog);
+        assertThat(msgs).noneMatch(m -> m.contains("regular expression"));
+
+        // RAW() is not part of the regex: the value inside it is what is 
checked
+        List<String> raw = SourceValidator.validateYamlEndpoints("""
+                - from:
+                    uri: file:input?include=RAW(*.txt)&noop=true
+                    steps:
+                      - log: "${body}"
+                """, catalog);
+        assertThat(raw).hasSize(1);
+        assertThat(raw.get(0)).contains("include=*.txt is not a regular 
expression").contains("antInclude=*.txt");
+    }
+
     @Test
     void aSimpleMistakeInAFileNameOptionIsReportedAtWriteTime() {
         // r26 connect-sftp-transfer step 3, a receipt named like the batch: 
the write was accepted, and the route then

Reply via email to