This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.22.x by this push:
new 29b9b5804430 [backport camel-4.22.x] CAMEL-25715: camel-jbang - camel
cmd eval sends the expression as it is (#27993)
29b9b5804430 is described below
commit 29b9b5804430710771e7cc567f5bbf25a764d2fa
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Oct 17 08:29:42 2026 +0200
[backport camel-4.22.x] CAMEL-25715: camel-jbang - camel cmd eval sends the
expression as it is (#27993)
camel cmd eval escaped the template and the body into the action file, and
the integration does not unescape them, so an expression with quotes or a slash
reached the language changed. Now they are sent as they are. Backport of #27979.
Co-authored-by: Claude Opus 5.5 (1M context) <[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"));
+ }
+}