Ticket #73: do not intercept 'cd' in compound commands - #5121
Conversation
|
|
||
| for (p = cmd; *p != '\0'; p++) | ||
| { | ||
| if (*p == ';' && (p == cmd || *(p - 1) != '\\')) |
There was a problem hiding this comment.
this is unreliable. you need to parse forward.
| { | ||
| if (*p == ';' && (p == cmd || *(p - 1) != '\\')) | ||
| return TRUE; | ||
| if (p[0] == '&' && p[1] == '&') |
There was a problem hiding this comment.
why do you exclude single amps and pipes?
| */ | ||
|
|
||
| gboolean | ||
| has_shell_metacharacters (const char *cmd) |
There was a problem hiding this comment.
i think it would be better to use glib's shell_parse_argv() with NULL output arguments.
c5350f7 to
db89c89
Compare
| return TRUE; | ||
| } | ||
|
|
||
| for (p = cmd; *p != '\0'; p++) |
There was a problem hiding this comment.
huh, that's not what i meant. the idea is that you can entirely replace this code with the above call. the remaining comments were only for the case that the idea turns out infeasible.
after a second thought, the idea needs to be revised, of course: you actually need to use the output. that means that you need to weave it somewhat more deeply into enter() below instead of "bolting it on".
There was a problem hiding this comment.
It seems like the GLib doesn't treat ; as a command separator, causing errors for commands like cd ..;ls, cd /tmp;ls, cd ..&&ls, cd & or cd a&b.
On the other hand, a command like cd .. ; ls would work well with g_shell_parse_argv().
For that reason, a forward-parsing has_unquoted_metacharacters() pre-check is still there.
I have added more test cases.
There was a problem hiding this comment.
It seems like the GLib doesn't treat
;as a command separator,
huh, that looks like an outright bug.
maybe they tried fixing over-interpreting # inside words, and caused collateral damage.
There was a problem hiding this comment.
I found this comment: https://gitlab.gnome.org/GNOME/glib/-/blob/main/glib/gshell.c#L356
It seems like they claim it as a feature, not a bug.
I believe the right behavior for the MC is to be closest to the shell as possible.
@ossilator What do you think about reverting the last change and doing the parsing on our own?
There was a problem hiding this comment.
yeah, it seems that this function is too far removed from actual shells. i thought it would be closer to https://github.com/KDE/kcoreaddons/blob/master/src/lib/util/kshell_unix.cpp#L46 in AbortOnMeta mode. do only our own forward-parsing.
1836b8b to
17d31ab
Compare
17d31ab to
7243ff1
Compare
Skip internal cd handling when the command line contains unquoted shell metacharacters (; | &) or command substitution syntax ($( or `), letting the shell execute it instead. Double quotes suppress operators but not command substitution, matching real shell behavior. Signed-off-by: Marek Libra <marek.libra@gmail.com>
7243ff1 to
1c35906
Compare
ossilator
left a comment
There was a problem hiding this comment.
just a few optimization ideas.
note that didn't check the underlying assumptions about tolerable syntax.
|
|
||
| if (in_double_quote) | ||
| { | ||
| if (*p == '\\' && p[1] != '\0') |
289a242 to
c0209d1
Compare
|
@ossilator Can you please have a look at the last changes? |
|
@zyv Can you please have a look here? |
Signed-off-by: Marek Libra <marek.libra@gmail.com>
|
Maintainers, may I ask for review here? |
Sorry, I won't have time for |
|
Understood. Having an additional maintainer would definitely help address that issue. To my knowledge, the MC still has a large user base and a long list of contributors. I love this project - I've been using it for as long as I can remember. I grew up with Norton Commander and was looking for an alternative. Back then, in the ancient days... @zyv Good luck with your exams! |
I haven't talked to @aborodin in a while (for the same reasons), but I think he is still somewhat active - albeit he has had internet access problems recently. Maybe he can have a look and decide.
Sure, but like for most foundational open source projects, nobody is up to set up a couple of maintainers with a decent full-time job (maintaining those said projects). For companies, it's much better to extract short-term profit when they can - and why wouldn't they - it's capitalism after all, and for users it's great to get free stuff. Contributors are actually more of a problem than help, because most submit stuff that takes more time to review and get into shape than do it yourself (I haven't looked at your submission, so this is not in any way directed against it - just a general observation). The exceptions I've seen far are people who’ve got financially independent by completely other means, or indeed a few lucky ones who’ve got employed by FAANG maintaining their projects. I wouldn't mind it either - but so far it didn't work out for me that way.
Thanks, I'll definitively need it. |
|
@mareklibra Please squash commits in your branch and push forced as @ossilator asked you. |
Proposed changes
Skip internal cd handling when the command line contains unescaped ';', '&&', or '||', letting the shell execute it instead.
Checklist
👉 Our coding style can be found here: https://midnight-commander.org/coding-style/ 👈
git commit --amend -smake indent && make check)