Skip to content

Commit

Permalink
fix SwiftDocOrg#134: crash for operator functions when no baseURL.
Browse files Browse the repository at this point in the history
Fixes crashes like this:

```bash
$ swift doc generate my-repo/Sources --module-name MyRepo
2020-06-30T17:00:13-0400 critical: Unable to construct path for /(lhs:rhs:) with baseURL /
Fatal error: file /private/tmp/swift-doc-20200630-24417-jrxtfw/Sources/swift-doc/Supporting Types/Page.swift, line 55
zsh: illegal hardware instruction  swift doc generate my-repo/Sources --module-name MyRepo
```
  • Loading branch information
kareman committed Jul 1, 2020
1 parent d75fad6 commit 4cf215e
Showing 1 changed file with 2 additions and 16 deletions.
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 urlComponents = URL(string: baseURL)?.appendingPathComponent("\(identifier)")
guard let string = urlComponents?.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
}
}

0 comments on commit 4cf215e

Please sign in to comment.