mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
export: handle invalid identifiers
This commit is contained in:
parent
299e016a27
commit
3cdf7c3f76
2 changed files with 30 additions and 14 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/01 14:00:32 by khais #+# #+# */
|
/* Created: 2025/04/01 14:00:32 by khais #+# #+# */
|
||||||
/* Updated: 2025/04/01 14:08:53 by khais ### ########.fr */
|
/* Updated: 2025/04/01 15:53:06 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,25 +15,39 @@
|
||||||
#include "../../env/env_manip.h"
|
#include "../../env/env_manip.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
#include "../../ft_errno.h"
|
#include "../../ft_errno.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "../../parser/matchers/identifier.h"
|
||||||
|
|
||||||
|
static void single_export(char *arg, t_minishell *app)
|
||||||
|
{
|
||||||
|
char *key;
|
||||||
|
char *value;
|
||||||
|
|
||||||
|
if (ft_strchr(arg, '=') != NULL)
|
||||||
|
{
|
||||||
|
key = envp_get_key(arg);
|
||||||
|
value = envp_get_val(arg);
|
||||||
|
if (is_identifier(key) == false)
|
||||||
|
{
|
||||||
|
ft_dprintf(STDERR_FILENO,
|
||||||
|
"minishell: export: `%s': not a valid identifier\n", arg);
|
||||||
|
free2(key, value);
|
||||||
|
}
|
||||||
|
else if (env_set_entry(&app->env, key, value) == NULL)
|
||||||
|
ft_perror("minishell: export");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
t_builtin_type builtin_export(t_simple_cmd *cmd, t_minishell *app)
|
t_builtin_type builtin_export(t_simple_cmd *cmd, t_minishell *app)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
t_worddesc *arg;
|
t_worddesc *arg;
|
||||||
char *key;
|
|
||||||
char *value;
|
|
||||||
|
|
||||||
i = 1;
|
i = 1;
|
||||||
arg = wordlist_get(cmd->words, i++);
|
arg = wordlist_get(cmd->words, i++);
|
||||||
while (arg != NULL)
|
while (arg != NULL)
|
||||||
{
|
{
|
||||||
if (ft_strchr(arg->word, '=') != NULL)
|
single_export(arg->word, app);
|
||||||
{
|
|
||||||
key = envp_get_key(arg->word);
|
|
||||||
value = envp_get_val(arg->word);
|
|
||||||
if (env_set_entry(&app->env, key, value) == NULL)
|
|
||||||
ft_perror("minishell: export");
|
|
||||||
}
|
|
||||||
arg = wordlist_get(cmd->words, i++);
|
arg = wordlist_get(cmd->words, i++);
|
||||||
}
|
}
|
||||||
return (BUILTIN_EXPORT);
|
return (BUILTIN_EXPORT);
|
||||||
|
|
|
||||||
10
test.sh
10
test.sh
|
|
@ -318,13 +318,15 @@ blue=[]
|
||||||
blue=
|
blue=
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
when_run <<EOF "export with invalid identifiers"
|
when_run <<"EOF" "export with invalid identifiers"
|
||||||
export =
|
export = 123=456 hello=hi 456=789
|
||||||
export 123=456
|
echo hello=$hello
|
||||||
EOF
|
EOF
|
||||||
todo <<"EOF"
|
expecting <<"EOF"
|
||||||
minishell: export: `=': not a valid identifier
|
minishell: export: `=': not a valid identifier
|
||||||
minishell: export: `123=456': not a valid identifier
|
minishell: export: `123=456': not a valid identifier
|
||||||
|
minishell: export: `456=789': not a valid identifier
|
||||||
|
hello=hi
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
when_run <<EOF "quoted parentheses are not operators"
|
when_run <<EOF "quoted parentheses are not operators"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue