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


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/EndpointChecks.java:
##########
@@ -229,6 +230,42 @@ && countLeadingSpaces(lines[k + 1]) > paramIndent) {
         return errors;
     }
 
+    /**
+     * The value of an option under parameters: as the runtime reads it whole. 
The YAML DSL adds the parameters to the
+     * uri as they are written, so an & in a value starts a new option: 
filterFile: "${file:name} contains 'R&D'" is
+     * read as filterFile=${file:name} contains 'R and an option D', and the 
route fails to start (CAMEL-26591). That is
+     * said with the fix, RAW(...), which Camel keeps as it is, and the value 
is returned in RAW(...), so that the
+     * checks of the uri see the real options and values. A secret option is 
in RAW(...) already (the YAML DSL puts it
+     * there), and a path option goes in the path, where an & is a character 
like any other.
+     */
+    static String wholeValue(List<String> errors, CamelCatalog catalog, String 
scheme, String key, String value, int lineIdx) {
+        if (value.indexOf('&') < 0 || value.startsWith("RAW(") || 
value.startsWith("RAW{")) {
+            return value;
+        }
+        // RAW(...) ends at a ) followed by &, RAW{...} at a } followed by &
+        String raw = !value.contains(")&") ? "RAW(" + value + ")" : 
!value.contains("}&") ? "RAW{" + value + "}" : null;
+        if (raw == null) {
+            return value;

Review Comment:
   ⚠️ **Silent failure on values with both `)&` and `}&`**
   
   When a parameter value contains both `)&` and `}&` (e.g. `RAW(x)&y}&z`), 
`raw` is `null` and this returns the original value with no error. The 
downstream URI builder then splits on `&`, producing the same confusing 
"Unknown option" errors that this check is meant to replace — with no mention 
of the cause or the fix.
   
   ```suggestion
           if (raw == null) {
               // neither RAW(...) nor RAW{...} can wrap a value that contains 
both )& and }&
               errors.add(linePrefix(lineIdx) + scheme + ": " + key + " has an 
& in its value, and it"
                          + " cannot be wrapped in RAW(...) (contains )&) or 
RAW{...} (contains }&)."
                          + " Percent-encode the & as %26, or restructure the 
value.");
               return value;
           }
   ```



-- 
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