gnodet-bot commented on code in PR #26637:
URL: https://github.com/apache/camel/pull/26637#discussion_r4058090609


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/EndpointChecks.java:
##########
@@ -326,6 +326,14 @@ static void checkRegexOptions(List<String> errors, String 
fullUri, int uriLineId
             if (!name.equals("include") && !name.equals("exclude") || 
value.startsWith("{{")) {
                 continue;
             }
+            if (value.contains("\\\\")) {
+                // '.*\\.json$' in single quotes: YAML keeps both backslashes, 
and the regex then matches a file name
+                // with a literal backslash, so no file matches and the route 
runs in silence (CAMEL-24854)
+                errors.add(linePrefix(optionLineMap.getOrDefault(name, 
uriLineIdx)) + fullUri.substring(0, colon) + ": "
+                           + name + "=" + value + " matches a backslash in the 
file name (in single quotes one backslash"
+                           + " escapes the dot): write " + name + "='" + 
value.replace("\\\\", "\\") + "'");

Review Comment:
   ⚠️ **Misleading error message**: the phrase `"in single quotes one backslash 
escapes the dot"` is factually wrong YAML semantics. In YAML single-quoted 
scalars, backslash has *no* special meaning — it is always literal. There is no 
backslash-escaping in single-quoted YAML.
   
   The actual explanation is about *regex* escaping: in a regex, `\.` matches a 
literal dot, whereas `\\.` matches a backslash followed by any character. The 
user's mistake is applying Java string escaping (`\\` → `\`) to a YAML 
single-quoted string where it isn't needed.
   
   Suggest rephrasing:
   ```suggestion
                   errors.add(linePrefix(optionLineMap.getOrDefault(name, 
uriLineIdx)) + fullUri.substring(0, colon) + ": "
                              + name + "=" + value + " matches a backslash in 
the file name (in a regex, write \\\\." 
                              + " as \\. to match a literal dot): write " + 
name + "='" + value.replace("\\\\", "\\") + "'");
   ```



##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/EndpointChecks.java:
##########
@@ -326,6 +326,14 @@ static void checkRegexOptions(List<String> errors, String 
fullUri, int uriLineId
             if (!name.equals("include") && !name.equals("exclude") || 
value.startsWith("{{")) {
                 continue;
             }
+            if (value.contains("\\\\")) {

Review Comment:
   ⚠️ **False positive on intentional `\\` in regex**: `value.contains("\\\\")` 
fires on *any* doubled backslash, including a legitimately intended one. For 
example, `include='.*\\\\myfile.*'` (YAML single-quoted) would produce a value 
`.*\\myfile.*` — a valid regex matching a backslash before `myfile` — but this 
check would flag it and suggest corrupting the regex to `.*\myfile.*`.
   
   Consider also checking whether the doubled backslash precedes a dot (the 
specific pattern from the bug report, `\\\.`), which is far less ambiguous as a 
user mistake:
   ```suggestion
               if (value.contains("\\\\.")) {
   ```
   This would still catch the `.*\\.json$` case (backslash-dot) while avoiding 
false positives on patterns that intentionally match a path separator or other 
literal backslash.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to