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

davsclaus pushed a commit to branch backport/27979-to-camel-4.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 690c93ea50982c668799661f695a72e40edb715c
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Oct 17 08:01:36 2026 +0200

    CAMEL-25715: camel-jbang - camel cmd eval sends the expression as it is
    
    camel cmd eval JSON-escaped the expression and the body before putting
    them in the action, which is JSON already. The eval action of the CLI
    connector reads the values as they are, so an expression with a double
    quote failed, such as ${body} == "hello", and a slash, as in every
    XPath, or a quote in the body became part of the text.
    
    Backport of #27979 to camel-4.22.x, where only EvalExpressionCommand
    has the bug (the AI tools of main are not on this branch).
    
    Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../commands/action/EvalExpressionCommand.java     |  5 ++-
 .../commands/action/EvalExpressionCommandTest.java | 52 ++++++++++++++++++++++
 2 files changed, 55 insertions(+), 2 deletions(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/EvalExpressionCommand.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/EvalExpressionCommand.java
index 1501c278f966..b1dfe1f3705f 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/EvalExpressionCommand.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/EvalExpressionCommand.java
@@ -151,9 +151,10 @@ public class EvalExpressionCommand extends 
ActionWatchCommand {
         root.put("action", "eval");
         root.put("language", language);
         root.put("predicate", predicate);
-        root.put("template", Jsoner.escape(template));
+        // as they are: the action file is JSON, and the integration does not 
unescape them
+        root.put("template", template);
         if (body != null) {
-            root.put("body", Jsoner.escape(body));
+            root.put("body", body);
         }
         if (headers != null) {
             JsonArray arr = new JsonArray();
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/action/EvalExpressionCommandTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/action/EvalExpressionCommandTest.java
new file mode 100644
index 000000000000..52d4c9b88f55
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/action/EvalExpressionCommandTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.dsl.jbang.core.commands.action;
+
+import java.util.Map;
+
+import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
+import org.apache.camel.util.json.JsonObject;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import picocli.CommandLine;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+@ExtendWith(MockitoExtension.class)
+class EvalExpressionCommandTest extends ActionCommandTestSupport {
+
+    @Test
+    void testTheExpressionAndBodyAreSentAsTheyAre() throws Exception {
+        writeStatusFile(TEST_PID, "orders");
+
+        EvalExpressionCommand command = new EvalExpressionCommand(new 
CamelJBangMain().withPrinter(printer));
+        CommandLine.populateCommand(command, "orders", "--template=${body} 
contains \"/\"",
+                "--body={\"path\":\"a/b\"}");
+
+        int exit = callWithResponse(command, new JsonObject(Map.of("status", 
"success", "result", "true")));
+
+        assertEquals(0, exit);
+        // the integration does not unescape them: escaped, the quotes and 
slashes would be part of the expression
+        JsonObject action = readActionFile(TEST_PID);
+        assertNotNull(action, "action file should be written for the matched 
process");
+        assertEquals("eval", action.getString("action"));
+        assertEquals("${body} contains \"/\"", action.getString("template"));
+        assertEquals("{\"path\":\"a/b\"}", action.getString("body"));
+    }
+}

Reply via email to