Skip to content

Commit 5683ee0

Browse files
committed
Fix evaluation of env value
If the value is dynamically obtained from an environment variable, an empty string is set for the non-existing variable. This change prevents writing the artifacts to an invalid / prohibited location.
1 parent e7b7722 commit 5683ee0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Sources/SnapshotTesting/AssertSnapshot.swift

+7-4
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,13 @@ public func verifySnapshot<Value, Format>(
301301
return nil
302302
}
303303

304-
let artifactsUrl = URL(
305-
fileURLWithPath: ProcessInfo.processInfo.environment["SNAPSHOT_ARTIFACTS"]
306-
?? NSTemporaryDirectory(), isDirectory: true
307-
)
304+
let artifactsDirectory: String
305+
if let value = ProcessInfo.processInfo.environment["SNAPSHOT_ARTIFACTS"], !value.isEmpty {
306+
artifactsDirectory = value
307+
} else {
308+
artifactsDirectory = NSTemporaryDirectory()
309+
}
310+
let artifactsUrl = URL(fileURLWithPath: artifactsDirectory, isDirectory: true)
308311
let artifactsSubUrl = artifactsUrl.appendingPathComponent(fileName)
309312
try fileManager.createDirectory(at: artifactsSubUrl, withIntermediateDirectories: true)
310313
let failedSnapshotFileUrl = artifactsSubUrl.appendingPathComponent(

0 commit comments

Comments
 (0)