7
93
Fork
You've already forked wmenu
22

Spaces not escaped #62

Open
opened 2025年06月19日 19:46:39 +02:00 by morcant · 5 comments

What happens

  • I have a command called Gorx Planet, which starts up a game that I'm working on
  • When I type in gorx, Gorx Planet appears as an option to select
  • I press Tab to autocomplete the entry, then Enter
  • Nothing happens, wmenu simply exits; Gorx Planet &> /tmp/error.log shows only an empty file
  • If I wrap the command in quotation marks, like 'Gorx Planet', or escape the space with a backslash, like Gorx\ Planet, the game successfully launches as expected; however, quoting or escaping the space causes the command to no longer show up as a suggested application, despite allowing me to launch it

Expected Behavior

  • If the command shows up as Gorx Planet in the autocompletion list, I expect to be able to: select it with Tab, and launch it with Enter
  • Pressing Tab would either automatically quote or escape the command with spaces, or handle the escaping of spaces unbeknowst to the user in the background
  • If the command will launch with 'Gorx Planet' or Gorx\ Planet, I would expect it to show up in the autocompletion list

I'm fairly confident that this is an issue with spaces not being escaped. I would be happy to look into this more, if you wouldn't mind pointing me in the right direction as to where this escaping of spaces might take place.

### What happens - I have a command called `Gorx Planet`, which starts up a game that I'm working on - When I type in `gorx`, `Gorx Planet` appears as an option to select - I press Tab to autocomplete the entry, then Enter - Nothing happens, wmenu simply exits; `Gorx Planet &> /tmp/error.log` shows only an empty file - If I wrap the command in quotation marks, like `'Gorx Planet'`, or escape the space with a backslash, like `Gorx\ Planet`, the game successfully launches as expected; however, quoting or escaping the space causes the command to no longer show up as a suggested application, despite allowing me to launch it ### Expected Behavior - If the command shows up as `Gorx Planet` in the autocompletion list, I expect to be able to: select it with Tab, and launch it with Enter - Pressing Tab would either automatically quote or escape the command with spaces, or handle the escaping of spaces unbeknowst to the user in the background - If the command will launch with `'Gorx Planet'` or `Gorx\ Planet`, I would expect it to show up in the autocompletion list I'm fairly confident that this is an issue with spaces not being escaped. I would be happy to look into this more, if you wouldn't mind pointing me in the right direction as to where this escaping of spaces might take place.

Interesting, I hadn't considered that executable filenames might contain spaces. Do you know if dmenu is able to launch the program?

Interesting, I hadn't considered that executable filenames might contain spaces. Do you know if dmenu is able to launch the program?
Author
Copy link

Yeah, it is able to launch the program, as long as I use quotes or a backslash to escape the space. It's not a huge deal, but I figured I'd document the behavior 😃

Yeah, it is able to launch the program, as long as I use quotes or a backslash to escape the space. It's not a huge deal, but I figured I'd document the behavior 😃
Author
Copy link

I think I figured it out!

I found that commands were being executed with execvp. I've never used these before, but started by testing out a command with a space in the name.

#include <unistd.h> 
#include <stdio.h> 
#include <errno.h> 
#include <string.h> 
 
char * execvp_command_array[] = {"space command", NULL}; 
 
int main(int argc, char *const argv[]) { 
 const int failure_err_code = execvp(execvp_command_array[0], execvp_command_array);
 printf("Command 'execvp' failed with error message: %s\n", strerror(errno));
 return failure_err_code;
}

As long as I have a the command "space command" in my path, this works just fine. However, the command is being run through /bin/sh -c.

#include <unistd.h> 
#include <stdio.h> 
#include <errno.h> 
#include <string.h> 
 
char * execvp_command_array[] = {"/bin/sh", "-c", "space command", NULL}; 
 
int main(int argc, char *const argv[]) { 
 const int failure_err_code = execvp(execvp_command_array[0], execvp_command_array);
 printf("Command 'execvp' failed with error message: %s\n", strerror(errno));
 return failure_err_code;
}

This doesn't work, and I get the error message that the command space does not exist. Bash grammar says that blank spaces separate commands and arguments, so this sort of makes sense I guess.

I don't have a solution for this problem that isn't really a problem, but may I ask - why envoke the command with /bin/sh -c? Does this ensure the user's .profile or .bash_profile is included before running the command?

Thanks for your time.

I think I figured it out! I found that commands were being executed with execvp. I've never used these before, but started by testing out a command with a space in the name. ``` #include <unistd.h> #include <stdio.h> #include <errno.h> #include <string.h> char * execvp_command_array[] = {"space command", NULL}; int main(int argc, char *const argv[]) { const int failure_err_code = execvp(execvp_command_array[0], execvp_command_array); printf("Command 'execvp' failed with error message: %s\n", strerror(errno)); return failure_err_code; } ``` As long as I have a the command "space command" in my path, this works just fine. However, the command is being run through `/bin/sh -c`. ``` #include <unistd.h> #include <stdio.h> #include <errno.h> #include <string.h> char * execvp_command_array[] = {"/bin/sh", "-c", "space command", NULL}; int main(int argc, char *const argv[]) { const int failure_err_code = execvp(execvp_command_array[0], execvp_command_array); printf("Command 'execvp' failed with error message: %s\n", strerror(errno)); return failure_err_code; } ``` This doesn't work, and I get the error message that the command `space` does not exist. Bash grammar says that blank spaces separate commands and arguments, so this sort of makes sense I guess. I don't have a solution for this problem that isn't really a problem, but may I ask - why envoke the command with `/bin/sh -c`? Does this ensure the user's .profile or .bash_profile is included before running the command? Thanks for your time.

@morcant I thought this was fixed at first because it worked fine for me but then I remembered I don't use wmenu-run but instead a shell script with wmenu.

Something like:

#! /bin/sh
menu="wmenu -i -l 25"
exec "$(/bin/ls $( printf $PATH |sed 's/:/ /g' ) | sort -u | $menu)"

doesn't have the issue.

@morcant I thought this was fixed at first because it worked fine for me but then I remembered I don't use wmenu-run but instead a shell script with wmenu. Something like: ``` #! /bin/sh menu="wmenu -i -l 25" exec "$(/bin/ls $( printf $PATH |sed 's/:/ /g' ) | sort -u | $menu)" ``` doesn't have the issue.

I think using /bin/sh -c might be incorrect in this case. Instead, we may need to feed the selected command directly into execvp.

I think using `/bin/sh -c` might be incorrect in this case. Instead, we may need to feed the selected command directly into `execvp`.
Sign in to join this conversation.
No Branch/Tag specified
main
0.2.0
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
3 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
adnano/wmenu#62
Reference in a new issue
adnano/wmenu
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?