diff --git a/generate_appcast/ArchiveItem.swift b/generate_appcast/ArchiveItem.swift index ed98016b..73533d8c 100644 --- a/generate_appcast/ArchiveItem.swift +++ b/generate_appcast/ArchiveItem.swift @@ -98,11 +98,14 @@ class ArchiveItem: CustomStringConvertible { return "\(self.archivePath) \(self.version)" } - var archiveURL: URL { - if let relative = self.feedURL { - return URL(string: self.archivePath.lastPathComponent, relativeTo: relative)! + var archiveURL: URL? { + guard let escapedFilename = self.archivePath.lastPathComponent.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else { + return nil; } - return URL(string: self.archivePath.lastPathComponent)! + if let relative = self.feedURL { + return URL(string: escapedFilename, relativeTo: relative) + } + return URL(string: escapedFilename) } var pubDate : String { diff --git a/generate_appcast/FeedXML.swift b/generate_appcast/FeedXML.swift index 9f21b1ab..5dbc8d0b 100644 --- a/generate_appcast/FeedXML.swift +++ b/generate_appcast/FeedXML.swift @@ -117,8 +117,11 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { item.addChild(enclosure!); } + guard let archiveURL = update.archiveURL?.absoluteString else { + throw makeError(code: .appcastError, "Bad archive name or feed URL"); + }; var attributes = [ - XMLNode.attribute(withName: "url", stringValue: update.archiveURL.absoluteString) as! XMLNode, + XMLNode.attribute(withName: "url", stringValue: archiveURL) as! XMLNode, XMLNode.attribute(withName: "sparkle:version", uri: sparkleNS, stringValue: update.version) as! XMLNode, XMLNode.attribute(withName: "length", stringValue: String(update.fileSize)) as! XMLNode, XMLNode.attribute(withName: "type", stringValue: update.mimeType) as! XMLNode,