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 fd13ce5cfbd0 CAMEL-24906: camel-yaml-dsl-validator - the quote hints
print the line to write (#26749)
fd13ce5cfbd0 is described below
commit fd13ce5cfbd06d845e1e1c7194e3c3214fa3c92e
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Sep 23 10:28:25 2026 +0200
CAMEL-24906: camel-yaml-dsl-validator - the quote hints print the line to
write (#26749)
An unclosed quote and a doubled closing quote now print the corrected line,
so the answer says what to write instead of where the parser stopped.
---
.../camel/dsl/yaml/validator/YamlValidator.java | 22 ++++++++++++++++------
.../validator/YamlValidatorPropertyHintTest.java | 22 +++++++++++++++++++++-
2 files changed, 37 insertions(+), 7 deletions(-)
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/YamlValidator.java
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/YamlValidator.java
index 2b47f748c2dc..47d4c69cd5c9 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/YamlValidator.java
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/YamlValidator.java
@@ -196,13 +196,19 @@ public class YamlValidator {
Matcher q =
Pattern.compile(":\\s*(\"(?:[^\"\\\\]|\\\\.)*\"|'[^']*')\\s*\\S").matcher(t);
if (q.find()) {
String key = t.trim().contains(":") ?
t.trim().substring(0, t.trim().indexOf(':')) : "the value";
+ String tail = t.substring(t.indexOf(q.group(1)) +
q.group(1).length()).strip();
+ // the value was corrected twice: it ends with two quotes,
not with a concatenation (CAMEL-24906)
+ String message = "\"".equals(tail)
+ ? "line " + last + ": the value of " + key + "
ends with two double quotes; remove the"
+ + " extra one and write the line as " +
t.strip().substring(0, t.strip().length() - 1)
+ : "line " + last + ": the value of " + key + "
continues after its closing quote"
+ + " (\"...\" + ...): a YAML value is one string,
there is no concatenation; a"
+ + " log message is a simple expression, write it
as one quoted text such as"
+ + " \">>> ${body}\"";
return Error.builder()
.messageKey("parser")
.format(new MessageFormat("{0}"))
- .arguments("line " + last + ": the value of " +
key + " continues after its closing quote"
- + " (\"...\" + ...): a YAML value is
one string, there is no concatenation; a"
- + " log message is a simple expression,
write it as one quoted text such as"
- + " \">>> ${body}\"")
+ .arguments(message)
.build();
}
}
@@ -280,8 +286,12 @@ public class YamlValidator {
String value = colon >= 0 ? line.substring(colon + 1).trim() :
line.trim();
long quotes = value.chars().filter(c -> c == '"').count() -
value.split("\\\\\"", -1).length + 1;
if (value.startsWith("\"") && quotes % 2 == 1) {
- return hint("line " + start.line() + ": the value opens a double
quote and never closes it: end it with"
- + " a \" after the last character (" + value + "\")");
+ // the line to write, not a description of the edit: a model
copies the line (CAMEL-24906)
+ String indent = line.substring(0, line.length() -
line.stripLeading().length());
+ String key = colon >= 0 ? line.stripLeading().substring(0,
line.stripLeading().indexOf(':') + 1) : "";
+ return hint("line " + start.line() + ": the value opens a double
quote and never closes it; write the line"
+ + " as " + (indent + key + " " + value + "\"").strip()
+ + " (a single quote inside a double-quoted value needs
no escape)");
}
return null;
}
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/YamlValidatorPropertyHintTest.java
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/YamlValidatorPropertyHintTest.java
index 03d33edc27a6..e41a7b1d7e7a 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/YamlValidatorPropertyHintTest.java
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/YamlValidatorPropertyHintTest.java
@@ -164,7 +164,27 @@ public class YamlValidatorPropertyHintTest {
- log: "done"
""");
assertThat(errors).extracting(Error::getMessage)
- .anyMatch(m -> m.startsWith("line 8: the value opens a double
quote and never closes it"));
+ .anyMatch(m -> m.startsWith("line 8: the value opens a double
quote and never closes it")
+ && m.contains("write the line as expression:
\"$[?(@.sku == '${header.sku}')]\""));
+ }
+
+ /** CAMEL-24906: the value corrected twice ends with two quotes, and the
line to write says so. */
+ @Test
+ public void testADoubledClosingQuoteIsNamed() throws Exception {
+ List<Error> errors = validator.validate("""
+ - route:
+ from:
+ uri: direct:a
+ steps:
+ - setBody:
+ expression:
+ jsonpath:
+ expression: "$[?(@.sku == '${header.sku}')]""
+ resultType: java.util.List
+ """);
+ assertThat(errors).extracting(Error::getMessage)
+ .anyMatch(m -> m.contains("ends with two double quotes; remove
the extra one")
+ && m.endsWith("write the line as expression:
\"$[?(@.sku == '${header.sku}')]\""));
}
@Test