cd: handle empty argument

This commit is contained in:
Khaïs COLIN 2025-03-31 17:05:30 +02:00
parent 8f3c15f096
commit f1b2e1e22d
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
2 changed files with 21 additions and 2 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/31 16:20:17 by khais #+# #+# */
/* Updated: 2025/03/31 16:56:16 by khais ### ########.fr */
/* Updated: 2025/03/31 17:05:21 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,7 +18,9 @@
static void ft_chdir(char *path, t_minishell *app)
{
if (chdir(path) == 0)
if (path[0] == '\0')
app->last_return_value = 0;
else if (chdir(path) == 0)
app->last_return_value = 0;
else
{

17
test.sh
View file

@ -210,6 +210,23 @@ minishell: cd: HOME not set
/tmp/dir.minishell
EOF
when_run <<EOF "cd with empty argument"
cd ""
pwd
EOF
expecting <<EOF
/tmp/dir.minishell
EOF
EXTRAENV="HOME="
when_run <<EOF "cd with no arguments and HOME equal to empty string"
cd
pwd
EOF
expecting <<EOF
/tmp/dir.minishell
EOF
when_run <<EOF "quoted parentheses are not operators"
echo unclosed '('
EOF