oscerd commented on PR #2966:
URL: https://github.com/apache/camel-kamelets/pull/2966#issuecomment-5398538717

   Fair point, and I've changed it — though not to a bean, because Camel 
already ships something better for this.
   
   `${file:onlyname}` is the built-in file language for "the file name with no 
leading paths", which is exactly the operation:
   
   ```yaml
   - setHeader:
       name: CamelFileName
       simple: "${header[file]}"
   - setHeader:
       name: CamelFileName
       simple: "${file:onlyname}"
   ```
   
   No regex, no new class, nothing for us to maintain, and the semantics are 
owned upstream.
   
   I looked at the bean route first. The precedent is `extract-field-action` 
(`beans:` + `process: ref:` against 
`org.apache.camel.component.kafka.transform.ExtractField`), but those helpers 
no longer live in this repo — `77be42a85` removed the module with *"Remove 
Camel-Kamelets-utils since it is now in core"*, and `camel-kamelets-utils` 
stops at 4.8.8 on Maven Central. So a bean would mean a PR to `apache/camel`, a 
Camel release, and then this one — for something the file language already does.
   
   Verified on 4.22.0, end to end through a Kamelet template rather than just 
the expression:
   
   | inbound header | file written |
   |---|---|
   | `file: ../../etc/evil.txt` | `evil.txt`, inside the configured directory |
   | `ce-file: sub/dir/report.csv` | `report.csv`, inside the configured 
directory |
   | *(none)* | exchange-id name, i.e. the default convention still applies |
   
   Two things worth your eye:
   
   1. The normalisation has to sit **inside** each `choice` branch. Applying it 
after the choice sets `CamelFileName` to an empty value when no header was 
supplied, which is not the same as leaving it unset — that third row is what 
catches it.
   2. `${file:onlyname}` leaves a bare `..` unchanged, where the previous regex 
blanked it. That names the parent directory rather than traversing into it, and 
the file/FTP producers reject it, so I took the trade for readability. Say the 
word if you'd rather it were handled explicitly.
   
   _Claude Code on behalf of Andrea Cosentino_


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