Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ final class _ProcessInfo: Sendable {
for env in environments {
let environmentString = String(cString: env)

#if os(Windows)
// Windows GetEnvironmentStringsW API can return
// magic environment variables set by the cmd shell
// that starts with `=`
// We should exclude these values
if environmentString.utf8.first == ._equal {
continue
}
#endif // os(Windows)

guard let delimiter = environmentString.firstIndex(of: "=") else {
continue
}
Expand Down
10 changes: 10 additions & 0 deletions Tests/FoundationEssentialsTests/ProcessInfoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,14 @@ final class ProcessInfoTests : XCTestCase {
processInfo.processName = originalProcessName
XCTAssertEqual(processInfo.processName, originalProcessName)
}

func testWindowsEnvironmentDoesNotContainMagicValues() {
// Windows GetEnvironmentStringsW API can return
// magic environment variables set by the cmd shell
// that starts with `=`
// This test makes sure we don't include these
// magic variables
let env = ProcessInfo.processInfo.environment
XCTAssertNil(env[""])
}
}