fix(subst/variable): invalid identifiers were having their $ swallowed

It is safe to delete this part:
```c
if (!rep)
   return (NULL);
```
because rep is always returned, and no other code depends on that value
This commit is contained in:
Khaïs COLIN 2025-04-16 17:36:51 +02:00
parent 733ae1093a
commit d53e40d3f4
2 changed files with 20 additions and 4 deletions

View file

@ -5,8 +5,8 @@
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/19 17:28/29 by khais #+# #+# */ /* Created: 2025/03/19 17:28:29 by khais #+# #+# */
/* Updated: 2025/03/24 10:52:10 by jguelen ### ########.fr */ /* Updated: 2025/04/16 17:45:36 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -95,9 +95,9 @@ static char *calculate_replacement(t_worddesc *word, t_minishell *app, size_t i,
{ {
*id_len = 1; *id_len = 1;
rep = expand_question_mark(app); rep = expand_question_mark(app);
if (!rep)
return (NULL);
} }
else if (*id_len == 0)
return (free(id), ft_strdup("$"));
else else
{ {
rep = env_get_val(app->env, id); rep = env_get_val(app->env, id);

16
test.sh
View file

@ -658,4 +658,20 @@ expecting <<EOF
hi hi
EOF EOF
when_run <<EOF "variable substitution with no valid name is not substitued"
echo \$=
echo \$:
EOF
expecting <<EOF
$=
$:
EOF
when_run <<EOF "variable substitution with a lone dollar sign"
echo " $ " | cat -e
EOF
expecting <<EOF
$ $
EOF
finalize finalize