hansva opened a new issue, #9301:
URL: https://github.com/apache/hop/issues/9301

   ### Apache Hop version?
   
   2.20.0
   
   ### Java version?
   
   21
   
   ### Operating system
   
   Other
   
   ### What happened?
   
   In the JavaScript transform, `lpad(value, filler, size)` and `rpad(value, 
filler, size)` never return when `filler` is an empty string and `value` is 
shorter than `size`. Both functions add the filler in a loop until the value 
reaches the size:
   
       while (valueToPad.length() < size) {
         valueToPad = filler + valueToPad;
       }
   
   With an empty filler the value never grows, so the loop never ends. The 
transform keeps one CPU core at 100% and the pipeline never finishes. The loop 
does not check whether the pipeline was stopped, so stopping it in the GUI does 
not end the thread either.
   
   The filler often comes from a field or a variable, so the hang can depend on 
the data: it starts with the first row where that field is empty.
   
   ### Steps to reproduce
   
   1. Generate rows: one row.
   2. JavaScript transform with the script `var padded = lpad("ab", "", 5);` 
and `padded` as an output field.
   3. Run the pipeline: it never finishes. The same happens with `rpad`.
   
   ### Proposed fix
   
   Stop the loop when the filler is empty, in both functions:
   
       while (!filler.isEmpty() && valueToPad.length() < size) {
   
   With an empty filler the value is returned unchanged, because nothing can 
pad it. A non-empty filler pads exactly as before.
   
   Two tests in `ScriptValuesAddedFunctionsTest`: an empty filler returns 
`"ab"` unchanged from both functions within a 5-second timeout, and `"*"` still 
pads `"ab"` to `"**ab"` and `"ab**"`.
   
   ### Issue Priority
   
   Priority: 2
   
   ### Issue Component
   
   Component: Transforms


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