Skip to content

Commit a1ee216

Browse files
authored
Fix infinite loop on Windows caused by checking path against "/". (#802)
1 parent 4a3def9 commit a1ee216

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Sources/SwiftFormat/API/Configuration.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,17 @@ public struct Configuration: Codable, Equatable {
410410
candidateDirectory.appendPathComponent("placeholder")
411411
}
412412
repeat {
413+
let previousDirectory = candidateDirectory
413414
candidateDirectory.deleteLastPathComponent()
415+
// if deleting a path component resulted in no change, terminate the loop
416+
if candidateDirectory == previousDirectory {
417+
break
418+
}
414419
let candidateFile = candidateDirectory.appendingPathComponent(".swift-format")
415420
if FileManager.default.isReadableFile(atPath: candidateFile.path) {
416421
return candidateFile
417422
}
418-
} while candidateDirectory.path != "/"
423+
} while true
419424

420425
return nil
421426
}

0 commit comments

Comments
 (0)