View Issue Details

IDProjectCategoryView StatusLast Update
0004050Far ManagerSpecial Symbolspublic2024-08-25 18:52
Reportermil_alex Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Platformx64OSWindowsOS Version7
Product Version3.0 
Summary0004050: wrong quoted path substitute
DescriptionHi. I'm using a my own command line Win32 exe utility via F2 user menu from Far 3.0.6300.0 x64 Win 7 x64

I need to pass the inactive panel path to the utility command line with optional keys, so I wrote first

cdel32.exe !#!\ -all

!\ means current path and !# means it for inactive Far panel

that works fine for paths without a space char inside.

when the path includes space characters like d:\telegram\telegram video\my cat
then macros !#!\ is replaced exactly with this string and breaks at every space found

so my utility gets 3 extra parameters instead of a single path string

I tried to work this out by adding quotes before and after the path macros:

cdel32.exe "!#!\" -all

I thought it would substitute the path with quotes and next pass the -all option.
however this way Far passed me the path padded by quote sign and -all too.
d:\telegram\telegram video\my cat" -all

that is, leading quota has been stripped and everything the rest is passed as a single command line parameter which is obviously wrong.

should be
cdel32.exe "d:\telegram\telegram video\my cat" -all

I guess the \" has some higher priority and broke the logic of substitute
Steps To Reproducecall F2 user menu
add any call of a command line executable with "!#!\" special symbols

the expected behavior is a quoted path of an inactive Far panel

wrong behavior is a path padded with ending quote sign and everything up to the end of menu string
Tagsuser menu;special characters
Build

Activities

HaRT

2024-08-24 14:41

reporter   bugnote:0017572

It's not FAR's fault, it substitutes all symbols in the template you provided and passes the resulting string to CMD for execution.
For example, if I use the following command for test: “python -c "import sys; print(sys.argv)" "!#!\" EOM”, I get the following output:
D:\dev>python -c "import sys; print(sys.argv)" "C:\Program Files\" EOM
['-c', 'C:\\Program Files" EOM']
which is consistent with your report.
However if I add an extra backslash to escape the closing quote: “python -c "import sys; print(sys.argv)" "!#!\\" EOM”, I get the expected result:
D:\dev>python -c "import sys; print(sys.argv)" "C:\Program Files\\" EOM
['-c', 'C:\\Program Files\\', 'EOM']
So you just need to insert the backslash.

mil_alex

2024-08-24 15:27

reporter   bugnote:0017573

Thank you. However it didn't help because an extra backslash I tried to add was just padded to the path, not escaping the quota sign.

that means in terms of my Issue example
d:\telegram\telegram video\my cat\" -all # this is argv[1] with 2 backslashes in macros
d:\telegram\telegram video\my cat" -all # this is argv[1] with one backslash in macros

IMHO in this piece of code the quotes should be treated like a pair of brackets, that is, we parse the menu command string and once the leading quote sign is found, walk to the right while it is not another quote sign, then substitute whatever is in the middle.

This way one would get !#!\ which is well documented.

Leading quote sign is either the start of a string, or a 1st quote sign after a space between the command line parameters.

If Far encountered quoted something, it should quote the substituted result as well, tp prevent paths with spaces be split at every space.

then parse or cat the rest of menu command line, because it is possible to pass more than one quoted command line parameter at a time.

as I can see it.

probably it would be easier to check substituted results and when spaces found embrace it with quotes - always or with an extra check box :(

HaRT

2024-08-24 15:52

reporter   bugnote:0017574

that means in terms of my Issue example

mil_alex
Can you please provide the output similar to mine that shows the entire string FAR uses to run your command? It is possible the wrong parsing happens between that string and your argv[1].

mil_alex

2024-08-25 18:29

reporter   bugnote:0017575

Last edited: 2024-08-25 18:52

I have moved exe to the root of p: to keep screen output short
the menu commend string is cdel32.exe "!#!\\" -all

output is the following (1st line is the way Far calls my executable, two next lines are zero based argv strings)

P:\>cdel32.exe "C:\telegram\telegram desktop\tele\my video\\" -all
0 P:\cdel32.exe
1 C:\telegram\telegram desktop\tele\my video\" -all

if I use one backslash cdel32.exe "!#!\" -all
then output is similar

P:\>cdel32.exe "C:\telegram\telegram desktop\tele\my video\" -all
0 P:\cdel32.exe
1 C:\telegram\telegram desktop\tele\my video" -all

I think the rightmost quote sign should not be escaped here because an entire !\ is a special symbol to be evaluated, unlike the alone backslash somewhere followed by a char we would like to escape.

it seems that string match to a !\ should have higher priority than escape of a desired char that follows this special symbol

-- upd
it looks like that ending backslash in a path leads to the 2nd quote sign being escaped and therefore the rest of command line passed to a single argv item

Issue History

Date Modified Username Field Change
2024-08-24 12:41 mil_alex New Issue
2024-08-24 12:41 mil_alex Tag Attached: user menu;special characters
2024-08-24 14:41 HaRT Note Added: 0017572
2024-08-24 15:27 mil_alex Note Added: 0017573
2024-08-24 15:52 HaRT Note Added: 0017574
2024-08-25 18:29 mil_alex Note Added: 0017575
2024-08-25 18:52 mil_alex Note Edited: 0017575