From bba553bea5938932518dc6382e464968ce8374b4 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Wed, 15 May 2024 22:22:40 -0700 Subject: fix(ext/node): homedir() `getpwuid`/`SHGetKnownFolderPath` fallback (#23841) **Unix**: Returns the value of the HOME environment variable if it is set even if it is an empty string. Otherwise, it tries to determine the home directory by invoking the [getpwuid_r](https://linux.die.net/man/3/getpwuid_r) function with the UID of the current user. **Windows**: Returns the value of the USERPROFILE environment variable if it is set and it is not an empty string. Otherwise, it tries to determine the home directory by invoking the [SHGetKnownFolderPath](https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath) function with [FOLDERID_Profile](https://learn.microsoft.com/en-us/windows/win32/shell/knownfolderid). Fixes https://github.com/denoland/deno/issues/23824 --- tests/unit_node/os_test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/unit_node') diff --git a/tests/unit_node/os_test.ts b/tests/unit_node/os_test.ts index 9ce9fc9eb..810c22518 100644 --- a/tests/unit_node/os_test.ts +++ b/tests/unit_node/os_test.ts @@ -47,6 +47,14 @@ Deno.test({ }, }); +Deno.test({ + name: "home directory when HOME is not set", + fn() { + Deno.env.delete("HOME"); + assertEquals(typeof os.homedir(), "string"); + }, +}); + Deno.test({ name: "tmp directory is a string", fn() { -- cgit v1.2.3