Skip to content

Ticket #73: do not intercept 'cd' in compound commands#5121

Open
mareklibra wants to merge 2 commits into
MidnightCommander:masterfrom
mareklibra:issue.73.cdSemicolon
Open

Ticket #73: do not intercept 'cd' in compound commands#5121
mareklibra wants to merge 2 commits into
MidnightCommander:masterfrom
mareklibra:issue.73.cdSemicolon

Conversation

@mareklibra
Copy link
Copy Markdown

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/ 👈

  • I have referenced the issue(s) resolved by this PR (if any)
  • I have signed-off my contribution with git commit --amend -s
  • Lint and unit tests pass locally with my changes (make indent && make check)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

@github-actions github-actions Bot added needs triage Needs triage by maintainers prio: medium Has the potential to affect progress labels May 27, 2026
@github-actions github-actions Bot added this to the Future Releases milestone May 27, 2026
Comment thread src/filemanager/command.c Outdated

for (p = cmd; *p != '\0'; p++)
{
if (*p == ';' && (p == cmd || *(p - 1) != '\\'))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is unreliable. you need to parse forward.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread src/filemanager/command.c Outdated
{
if (*p == ';' && (p == cmd || *(p - 1) != '\\'))
return TRUE;
if (p[0] == '&' && p[1] == '&')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you exclude single amps and pipes?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

Comment thread src/filemanager/command.c Outdated
*/

gboolean
has_shell_metacharacters (const char *cmd)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it would be better to use glib's shell_parse_argv() with NULL output arguments.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used for validation

Skip internal cd handling when the command line contains
unescaped ';', '&&', or '||', letting the shell execute
it instead.

Signed-off-by: Marek Libra <marek.libra@gmail.com>
@mareklibra mareklibra force-pushed the issue.73.cdSemicolon branch from c5350f7 to db89c89 Compare May 27, 2026 12:53
Comment thread src/filemanager/command.c
return TRUE;
}

for (p = cmd; *p != '\0'; p++)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mareklibra mareklibra force-pushed the issue.73.cdSemicolon branch from 0002ffe to 1836b8b Compare May 29, 2026 08:29
Signed-off-by: Marek Libra <marek.libra@gmail.com>
@mareklibra mareklibra force-pushed the issue.73.cdSemicolon branch from 1836b8b to 17d31ab Compare May 29, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs triage Needs triage by maintainers prio: medium Has the potential to affect progress

Development

Successfully merging this pull request may close these issues.

savannah: ';' separated UNIX commands started from cd

2 participants