Bug 422133 - Wrong parameter end detection in useraction expansion
Summary: Wrong parameter end detection in useraction expansion
Status: REPORTED
Alias: None
Product: krusader
Classification: Applications
Component: general (show other bugs)
Version: 2.7.2
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Krusader Bugs Distribution List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-27 10:30 UTC by Wladimir Palant
Modified: 2020-05-27 10:30 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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