Bug 422133

Summary: Wrong parameter end detection in useraction expansion
Product: [Applications] krusader Reporter: Wladimir Palant <psbkde>
Component: generalAssignee: Krusader Bugs Distribution List <krusader-bugs-null>
Status: REPORTED ---    
Severity: normal CC: krusader-bugs-null
Priority: NOR    
Version First Reported In: 2.7.2   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Wladimir Palant 2020-05-27 10:30:33 UTC
SUMMARY
I am attempting to create a "copy in same directory" useraction (Shift+F5 in Total Commander). However, I noticed that placeholder expansion won't work correctly starting with the third nesting level.

You can see the issue under https://github.com/KDE/krusader/blob/3766d4106642e15c5970ff51b768271ae4bab3f2/krusader/UserAction/expander.cpp#L1131. The algorithm deciding whether we are in quotes right now is overly simple and will fail on the following construct for example:

%a("%b("%c("x","y")")%")%

It will assume that "%b("%c("x" is the first parameter of the %a()% placeholder (even number of quotation marks) and evaluate it on its own, hence the "unterminated %" error. The algorithm needs to recognize nested placeholders properly, not merely quotation marks.

STEPS TO REPRODUCE
1. Create a user action with the following command:

%_Copy("%aCurrent("yes", "no")%", "%_Ask("New file name", "%aCurrent("yes", "no")%")%")%

2. Run the user action.

OBSERVED RESULT
Error: unterminated % in Expander

EXPECTED RESULT
The useraction runs and allows copying a file. This is what I get if I remove the second parameter from the second %aCurrent()% placeholder, at the cost of unnecessary backslashes being added for some file names.

SOFTWARE/OS VERSIONS
Linux: Kubuntu 20.04
KDE Plasma Version: 5.18.5
KDE Frameworks Version: 5.68.0
Qt Version: 5.12.8