davsclaus commented on PR #27832:
URL: https://github.com/apache/camel/pull/27832#issuecomment-6185002234

   @ramu11 I pushed one commit to this branch (3e9bee540db1) so we can wrap 
this up. It replaces the hand-written encoding code with `camel-util`. The 
earlier rounds kept going back and forth for one reason, so here it is:
   
   **Root cause.** The advanced options were copied *after* 
`URISupport.resolveRawParameterValues(parameters)` in 
`KameletComponent.createEndpoint`. At that point RAW values are literal 
(`a&b`), but every other value is still percent-encoded (`a%26b`), because 
`useRawUri()` is `true`. `wrapRawIfNeeded` then had to guess how to turn that 
mix back into URI text. It can't tell a literal `%` or `+` from an encoded one, 
which is what @allthingssecurity's matrix showed. The bracket-depth splitter in 
`removeQueryParameter` was a second, home-made URI parser that didn't always 
agree with Camel's.
   
   **The change**
   - `KameletComponent` keeps a copy of the parameters as written, before 
`resolveRawParameterValues` (lists copied too, since that method updates them 
in place). The advanced options are taken from that copy. They are already URI 
text, so they are appended unchanged, one `name=value` per value for a repeated 
parameter. `wrapRawIfNeeded` and `isRawToken` are removed.
   - `removeQueryParameter` splits the query with `URISupport.parseQuery(query, 
true, true)`. That is the parser Camel uses for endpoint URIs, and raw mode 
keeps the values as written. The URI is still returned unchanged when the 
parameter is not there. The bracket counter is removed.
   - Net: `Kamelet.java` goes from about 120 lines of encoding code to about 50.
   
   **Tests** (camel-kamelet: 140 run, 0 failures, 2 skipped; both new tests 
fail on 796852ee and pass now)
   - `sinkOptionsAreReceivedLikeOptionsOnTheEndpointItself`: a probe component 
records the parameters it receives. The same options 
(`filter=a%26b&name=caf%C3%A9&q=a+b&secret=RAW(p@ss&word%41)&tag=x&tag=y`) go 
once through the Kamelet with `advancedOptions=true` and once directly on the 
endpoint. The two maps must be equal, so a forwarded option behaves exactly 
like one set on the endpoint itself.
   - `removeQueryParameterSplitsTheQueryLikeCamel`: `RAW(p(ss)&other=1` (from 
my earlier comment).
   - `removeQueryParameterKeepsRepeatedAndEncodedValues`.
   - All existing RAW tests pass unchanged.
   
   The component doc (and its catalog copy) now has one sentence saying options 
are forwarded as written.
   
   One thing I found while testing, which this PR doesn't cause: `filter=a%26b` 
reaches a component as `filter=a` plus `b=` even with a plain 
`to("probe:x?filter=a%26b")`, with no Kamelet involved. So the test checks 
`%26` only through the equality with the direct endpoint. I'll look at that 
separately in core.
   
   _Claude Code on behalf of @davsclaus_
   


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