Skip to content

Commit 5deaac3

Browse files
authored
Package.computeDefaultName: support the Windows path separator
1 parent de29f55 commit 5deaac3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Sources/PackageModel/Package.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,16 @@ public struct PackageReference: JSONMappable, JSONSerializable, Codable, CustomS
138138
/// Compute the default name of a package given its URL.
139139
public static func computeDefaultName(fromURL url: String) -> String {
140140
// Get the last path component of the URL.
141-
var lastComponent = url.split(separator: "/", omittingEmptySubsequences: true).last ?? url[...]
141+
142+
#if os(Windows)
143+
let isSeparator : (Character) -> Bool = { $0 == "/" || $0 == "\\" }
144+
#else
145+
let isSeparator : (Character) -> Bool = { $0 == "/" }
146+
#endif
147+
let separatorIndex = url.lastIndex(where: isSeparator)
148+
let startIndex = separatorIndex.map { url.index(after: $0) } ?? url.startIndex
149+
150+
var lastComponent = url[startIndex...]
142151

143152
// Strip `.git` suffix if present.
144153
if lastComponent.hasSuffix(".git") {

0 commit comments

Comments
 (0)