Skip to content

Commit b2a29e0

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 dc46eeb commit b2a29e0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Sources/SnapshotTesting/AssertSnapshot.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,13 @@ public func verifySnapshot<Value, Format>(
278278
return nil
279279
}
280280

281-
let artifactsUrl = URL(
282-
fileURLWithPath: ProcessInfo.processInfo.environment["SNAPSHOT_ARTIFACTS"] ?? NSTemporaryDirectory(), isDirectory: true
283-
)
281+
let artifactsDirectory: String
282+
if let value = ProcessInfo.processInfo.environment["SNAPSHOT_ARTIFACTS"], !value.isEmpty {
283+
artifactsDirectory = value
284+
} else {
285+
artifactsDirectory = NSTemporaryDirectory()
286+
}
287+
let artifactsUrl = URL(fileURLWithPath: artifactsDirectory, isDirectory: true)
284288
let artifactsSubUrl = artifactsUrl.appendingPathComponent(fileName)
285289
try fileManager.createDirectory(at: artifactsSubUrl, withIntermediateDirectories: true)
286290
let failedSnapshotFileUrl = artifactsSubUrl.appendingPathComponent(snapshotFileUrl.lastPathComponent)

0 commit comments

Comments
 (0)