From c26e3d0a2cdef28711c032a9025bc917d9668ab0 Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Wed, 22 Jul 2026 17:53:19 +0300 Subject: [PATCH] fix(env): allow get without a value --- CHANGELOG.md | 2 ++ Makefile | 5 ++- src/host-env.c | 4 --- tests/test_host_env_cli.c | 71 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 tests/test_host_env_cli.c diff --git a/CHANGELOG.md b/CHANGELOG.md index 48d8200..4025fcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ versioning for release tags. ### Fixed +- Allow `host-env get` to read a variable without treating its absent value + argument as invalid input. - Filter unsupported OSC terminal control sequences from `host-shell` output without corrupting UTF-8 text. - Keep the `host-shell` login wrapper within the HostShell command trap limit. diff --git a/Makefile b/Makefile index d0b8949..41a8d1c 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later TOOLS = host-run host-multiview host-shell host-path host-reveal host-notify host-edit host-clip host-info host-download host-env -TEST_BINS = tests/test_host_common.out tests/test_host_command_builders.out tests/test_host_edit_command.out tests/test_host_download_command.out tests/test_host_terminal_filter.out +TEST_BINS = tests/test_host_common.out tests/test_host_command_builders.out tests/test_host_edit_command.out tests/test_host_download_command.out tests/test_host_terminal_filter.out tests/test_host_env_cli.out TEST_SCRIPTS = tests/test_package_layout.sh tests/test_ahi_driver_source.sh tests/test_runtime_source.sh include version.mk COMMON_HEADERS = src/host_common.h src/host_path.h src/host_capture.h src/host_base64.h src/host_clip_command.h src/host_download_command.h src/host_edit_command.h src/host_env_command.h src/host_info_command.h src/host_notify_command.h src/host_powershell.h src/host_reveal_command.h src/host_shell_command.h src/uae_pragmas.h @@ -128,6 +128,9 @@ tests/test_host_download_command.out: tests/test_host_download_command.c src/hos tests/test_host_terminal_filter.out: tests/test_host_terminal_filter.c src/host_terminal_filter.h $(HOST_CC) $(HOST_NATIVE_FLAGS) $(HOST_CFLAGS) tests/test_host_terminal_filter.c -o $@ +tests/test_host_env_cli.out: tests/test_host_env_cli.c src/host-env.c src/host_env_command.h src/host_common.h src/host_powershell.h + $(HOST_CC) $(HOST_NATIVE_FLAGS) $(HOST_CFLAGS) $(VERFLAGS) tests/test_host_env_cli.c -o $@ + debug: CFLAGS += -DDEBUG -g debug: clean all diff --git a/src/host-env.c b/src/host-env.c index 7e4e4fb..261e0aa 100644 --- a/src/host-env.c +++ b/src/host-env.c @@ -66,10 +66,6 @@ int main(int argc, char *argv[]) if (!require_name(argv[2])) { return HOST_RETURN_ERROR; } - if (!host_env_valid_value(argv[3])) { - printf("Environment variable values cannot contain line breaks\n"); - return HOST_RETURN_ERROR; - } if (windows) { if (!host_append_env_get_command_windows(command, sizeof(command), argv[2])) { printf("Command is too long\n"); diff --git a/tests/test_host_env_cli.c b/tests/test_host_env_cli.c new file mode 100644 index 0000000..ccf2ddd --- /dev/null +++ b/tests/test_host_env_cli.c @@ -0,0 +1,71 @@ +/* + * SPDX-FileCopyrightText: 2020-2026 Dimitris Panokostas + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include +#include +#include + +#define HOST_PLATFORM_POSIX 1 +#define HOST_PLATFORM_WINDOWS 3 + +static const char *captured_command; + +static int InitUAEResource(void) +{ + return 1; +} + +static int GetHostPlatform(void) +{ + return HOST_PLATFORM_POSIX; +} + +static int host_print_command_output(const char *command) +{ + captured_command = command; + return 0; +} + +#define HOST_CAPTURE_H +#define main host_env_main +#include "../src/host-env.c" +#undef main + +static void require(int condition, const char *message) +{ + if (!condition) { + fprintf(stderr, "%s\n", message); + exit(1); + } +} + +static void test_get_dispatch(void) +{ + char *argv[] = { "host-env", "get", "HOST_TOOLS_TEST", NULL }; + + captured_command = NULL; + require(host_env_main(3, argv) == 0, "get should dispatch successfully"); + require(captured_command != NULL, "get should execute a host command"); + require(strstr(captured_command, "HOST_TOOLS_TEST") != NULL, + "get command should contain the requested variable name"); +} + +static void test_set_dispatch(void) +{ + char *argv[] = { "host-env", "set", "HOST_TOOLS_TEST", "value with spaces", NULL }; + + captured_command = NULL; + require(host_env_main(4, argv) == 0, "set should dispatch successfully"); + require(captured_command != NULL, "set should execute a host command"); + require(strstr(captured_command, "value with spaces") != NULL, + "set command should contain the requested value"); +} + +int main(void) +{ + test_get_dispatch(); + test_set_dispatch(); + return 0; +}