1.0.25 no longer supports exec bindings with single or double quotes #2

Closed
opened 2022-09-29 17:56:14 -07:00 by auouymous · 6 comments

From https://phab.enlightenment.org/T9014

StrlistDecodeEscaped() splits the string at spaces, and quoted arguments that contain spaces are split into many arguments. A binding with exec echo '1 2' displays the single quotes because the quotes are passed in the arguments. And bindings with exec sh -c 'cmd1 arg1 ; cmd2' fail because the first single quote is not terminated.

The code does support escaping spaces as exec echo 1\ 2 and exec sh -c cmd1\ arg1\ ;\ cmd2 but that is harder to read with the escaped spaces and no quotes.

Could it be changed to detect single or double quotes and scan for the next non-escaped matching quote, and store the text between them in the argument?

The normal space escaping is also slightly flawed because cmd \\arg1\\ arg2 creates a single argument instead of two. This patch refactors the argument splitting to support escaping \ with \\, and escaping spaces or the current ' or " quote. Anyone using subshells will need to wrap the bind with "sh -c" but this patch restores most of the functionality.

From https://phab.enlightenment.org/T9014 StrlistDecodeEscaped() splits the string at spaces, and quoted arguments that contain spaces are split into many arguments. A binding with `exec echo '1 2'` displays the single quotes because the quotes are passed in the arguments. And bindings with `exec sh -c 'cmd1 arg1 ; cmd2'` fail because the first single quote is not terminated. The code does support escaping spaces as `exec echo 1\ 2` and `exec sh -c cmd1\ arg1\ ;\ cmd2` but that is harder to read with the escaped spaces and no quotes. Could it be changed to detect single or double quotes and scan for the next non-escaped matching quote, and store the text between them in the argument? The normal space escaping is also slightly flawed because `cmd \\arg1\\ arg2` creates a single argument instead of two. This patch refactors the argument splitting to support escaping `\` with `\\`, and escaping spaces or the current ' or " quote. Anyone using subshells will need to wrap the bind with "sh -c" but this patch restores most of the functionality.
Owner

Hi, I didn't get notifications about the phab ticket or this one so I just noticed it now.
I'll look at it as soon as possible.

Hi, I didn't get notifications about the phab ticket or this one so I just noticed it now. I'll look at it as soon as possible.
kw self-assigned this 2022-09-30 21:35:20 -07:00
Owner

I had some trouble with your patch and segvs on unmatched quoting and ended up making an alternative implementation (pushed).
Please let me know if you see problems with it.

I had some trouble with your patch and segvs on unmatched quoting and ended up making an alternative implementation (pushed). Please let me know if you see problems with it.
Owner

Assuming ok.

Assuming ok.
kw closed this issue 2022-10-20 08:50:55 -07:00
Author

Thank you, your fix works great. However, the execvp() in src/action.c EspawnApplication() is converting escape sequences. exec echo '1\n2' produces different output than echo '1\n2' does in the terminal.

for(int i = 0; i < argc; i++) fprintf(stderr, "[%d] %s\n", i, argv[i]);

Placing that before the execvp() shows that StrlistDecodeEscaped() is not the cause.

Thank you, your fix works great. However, the execvp() in src/action.c EspawnApplication() is converting escape sequences. `exec echo '1\n2'` produces different output than `echo '1\n2'` does in the terminal. ``` for(int i = 0; i < argc; i++) fprintf(stderr, "[%d] %s\n", i, argv[i]); ``` Placing that before the execvp() shows that StrlistDecodeEscaped() is not the cause.
Owner

Yeah, quoting is tricky, and I know that the exec quoting handling is not identical to the shell one.
But can you give an example where it is a problem?
Otherwise I'm inclined to leave things as they are :)

Yeah, quoting is tricky, and I know that the exec quoting handling is not identical to the shell one. But can you give an example where it is a problem? Otherwise I'm inclined to leave things as they are :)
Author

xvkbd -text can use escape sequences to automate tasks in programs, but all of mine appear to work fine.

The following program doesn't do it so execvp() might not be the problem.

#include <stdio.h>
#include <unistd.h>
int main( ){
    const char *args[] = {"echo", "1\\n2", NULL};
    execvp(args[0], args);
}
`xvkbd -text` can use escape sequences to automate tasks in programs, but all of mine appear to work fine. The following program doesn't do it so execvp() might not be the problem. ```c #include <stdio.h> #include <unistd.h> int main( ){ const char *args[] = {"echo", "1\\n2", NULL}; execvp(args[0], args); } ```
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: e16/e16#2
No description provided.