Skip to content

Commit 40ca820

Browse files
authored
Prevent null character in Windows home directory (#808) (#813)
1 parent 4d1dfb4 commit 40ca820

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Sources/FoundationEssentials/String/String+Path.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ extension String {
374374
guard GetEnvironmentVariableW(pwszVariable, $0.baseAddress, dwLength) == dwLength - 1 else {
375375
return nil
376376
}
377-
return String(decoding: $0, as: UTF16.self)
377+
return String(decodingCString: $0.baseAddress!, as: UTF16.self)
378378
}
379379
}
380380
}
@@ -436,7 +436,7 @@ extension String {
436436
guard GetUserProfileDirectoryW(hToken, $0.baseAddress, &dwcchSize) else {
437437
fatalError("unable to query user profile directory")
438438
}
439-
return String(decoding: $0, as: UTF16.self)
439+
return String(decodingCString: $0.baseAddress!, as: UTF16.self)
440440
}
441441
#else
442442
#if targetEnvironment(simulator)

Sources/FoundationEssentials/URL/URL.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,7 @@ public struct URL: Equatable, Sendable, Hashable {
13241324
if result.count > 1 && result.utf8.last == UInt8(ascii: "/") {
13251325
_ = result.popLast()
13261326
}
1327-
let charsToLeaveEncoded = Set([UInt8(ascii: "/")])
1327+
let charsToLeaveEncoded: Set<UInt8> = [._slash, 0]
13281328
return Parser.percentDecode(result, excluding: charsToLeaveEncoded) ?? ""
13291329
}
13301330

0 commit comments

Comments
 (0)