Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

fix #134: crash for operator functions when no baseURL. #139

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions Sources/swift-doc/Supporting Types/Page.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ func path(for symbol: Symbol, with baseURL: String) -> String {
}

func path(for identifier: CustomStringConvertible, with baseURL: String) -> String {
var urlComponents = URLComponents(string: baseURL)
urlComponents = urlComponents?.appendingPathComponent("\(identifier)")
guard let string = urlComponents?.string else {
let url = URL(string: baseURL)?.appendingPathComponent("\(identifier)")
guard let string = url?.path else {
logger.critical("Unable to construct path for \(identifier) with baseURL \(baseURL)")
fatalError()
}
Expand All @@ -65,16 +64,3 @@ func writeFile(_ data: Data, to url: URL) throws {
try data.write(to: url)
try fileManager.setAttributes([.posixPermissions: 0o744], ofItemAtPath: url.path)
}

// MARK: -

fileprivate extension URLComponents {
func appendingPathComponent(_ component: String) -> URLComponents? {
var urlComponents = self
var pathComponents = urlComponents.path.split(separator: "/").map { "\($0)" }
pathComponents.append(component)
urlComponents.path = "/" + pathComponents.joined(separator: "/")

return urlComponents
}
}