This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 305ef06df115 CAMEL-26316: camel-jbang - AI tools: a ternary value with
a single quote is rewritten in double quotes
305ef06df115 is described below
commit 305ef06df1153c338bf61f135396e794642facc3
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Oct 26 20:46:58 2026 +0100
CAMEL-26316: camel-jbang - AI tools: a ternary value with a single quote is
rewritten in double quotes
The rewrite of a top-level ternary left a value such as O'Brien unquoted,
which Simple then reads as a function. It is now quoted with double quotes.
Follow-up to a review comment on #28498.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../camel/dsl/jbang/core/commands/ai/SimpleChecks.java | 7 ++++++-
.../jbang/core/commands/ai/SourceValidatorSimpleTest.java | 12 ++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/SimpleChecks.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/SimpleChecks.java
index e5ee4d6e3bdd..0d40463c873c 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/SimpleChecks.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/SimpleChecks.java
@@ -269,12 +269,17 @@ final class SimpleChecks {
/**
* A value of the ternary: bare text is quoted, a quoted literal, a
function, a number, true, false and null not.
+ * Text with a single quote of its own (O'Brien) is quoted with double
quotes, and text with both quotes stays as
+ * written.
*/
private static String quoted(String value) {
if (value.isEmpty() || value.startsWith("'") || value.startsWith("\"")
|| value.startsWith("${")
- || value.matches("-?\\d+(\\.\\d+)?|true|false|null") ||
value.contains("'")) {
+ || value.matches("-?\\d+(\\.\\d+)?|true|false|null")) {
return value;
}
+ if (value.contains("'")) {
+ return value.contains("\"") ? value : "\"" + value + "\"";
+ }
return "'" + value + "'";
}
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/SourceValidatorSimpleTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/SourceValidatorSimpleTest.java
index 74a7261735b7..593d5058f278 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/SourceValidatorSimpleTest.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/SourceValidatorSimpleTest.java
@@ -453,6 +453,9 @@ class SourceValidatorSimpleTest {
// two functions compared: the condition starts with the first of them
assertThat(rewritten("${header.a} == ${header.b} ? same : 2"))
.isEqualTo("${header.a == ${header.b} ? 'same' : 2}");
+ // a value with a single quote of its own is quoted with double quotes
+ assertThat(rewritten("${header.vip} == true ? guest : O'Brien"))
+ .isEqualTo("${header.vip == true ? 'guest' : \"O'Brien\"}");
// no function before the ?: no rewrite, the message keeps its example
assertThat(SimpleChecks.topLevelTernary("Total 5 > 3 ? ${header.a} :
no"))
.endsWith("as in ${body.size() == 0 ? ${null} : ${body[0]}}");
@@ -465,6 +468,15 @@ class SourceValidatorSimpleTest {
simple: "%s"
""".formatted(rewritten("${header.CamelTimerCounter} == 1 ?
'order.json' : 'order-bad-email.json'")),
catalog)).isEmpty();
+ assertThat(SourceValidator.validateYamlSimple("""
+ - from:
+ uri: timer:tick
+ steps:
+ - setBody:
+ simple: |-
+ %s
+ """.formatted(rewritten("${header.vip} == true ? guest :
O'Brien")),
+ catalog)).isEmpty();
}
private static String rewritten(String text) {