diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index bdcbad68..f2a71c73 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -325,6 +325,7 @@ 7293A1AF1CEE933800B957A7 /* SPUURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7293A1AD1CEE933800B957A7 /* SPUURLRequest.m */; }; 7293A1B11CEE9B9F00B957A7 /* SPUURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7293A1AD1CEE933800B957A7 /* SPUURLRequest.m */; }; 729924941DF4A45000DBCDF5 /* SUUpdateValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = 729924931DF4A45000DBCDF5 /* SUUpdateValidator.m */; }; + 729F7EAC27366353004592DC /* test-links.xml in Resources */ = {isa = PBXBuildFile; fileRef = 729F7EAB27366353004592DC /* test-links.xml */; }; 72A1C2631CD6849C004CD282 /* SUUpdatePermissionPrompt.h in Headers */ = {isa = PBXBuildFile; fileRef = 612DCBAD0D488BC60015DBEA /* SUUpdatePermissionPrompt.h */; }; 72A450531C69A68900D67EEA /* SUUpdatePermissionResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 72A450511C69A68900D67EEA /* SUUpdatePermissionResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72A450541C69A68900D67EEA /* SUUpdatePermissionResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 72A450521C69A68900D67EEA /* SUUpdatePermissionResponse.m */; }; @@ -1227,6 +1228,7 @@ 729BB3D11D503826007C4276 /* org.sparkle-project.Downloader.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = "org.sparkle-project.Downloader.entitlements"; path = "Downloader/org.sparkle-project.Downloader.entitlements"; sourceTree = SOURCE_ROOT; }; 729F10FD1C65A9B500DFCCC5 /* ConfigUITest.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITest.xcconfig; sourceTree = ""; }; 729F10FE1C65A9B500DFCCC5 /* ConfigUITestCoverage.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITestCoverage.xcconfig; sourceTree = ""; }; + 729F7EAB27366353004592DC /* test-links.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "test-links.xml"; sourceTree = ""; }; 72A450511C69A68900D67EEA /* SUUpdatePermissionResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdatePermissionResponse.h; sourceTree = ""; }; 72A450521C69A68900D67EEA /* SUUpdatePermissionResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdatePermissionResponse.m; sourceTree = ""; }; 72A4A23F1BB6567D00E7820D /* SUFileManagerTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUFileManagerTest.swift; sourceTree = ""; }; @@ -1709,6 +1711,7 @@ 5F1510A11C96E591006E1629 /* testnamespaces.xml */, FA30773C24CBC295007BA37D /* testlocalizedreleasenotesappcast.xml */, 5A5DD41B249F0F4B0045EB3E /* test-relative-urls.xml */, + 729F7EAB27366353004592DC /* test-links.xml */, 5A5DD40324958AFF0045EB3E /* SUUpdateValidatorTest */, ); path = Resources; @@ -2973,6 +2976,7 @@ 722545B626805FF80036465C /* testappcast_info_updates.xml in Resources */, 7202DC9A269ABD3500737EC4 /* testappcast_phasedRollout.xml in Resources */, 5F1510A21C96E591006E1629 /* testnamespaces.xml in Resources */, + 729F7EAC27366353004592DC /* test-links.xml in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 8b360079..63c5ef28 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -385,10 +385,17 @@ static NSString *SUAppcastItemStateKey = @"SUAppcastItemState"; if (![theInfoURL isKindOfClass:[NSString class]]) { SULog(SULogLevelError, @"%@ -%@ Info URL is not of valid type.", NSStringFromClass([self class]), NSStringFromSelector(_cmd)); } else { + NSURL *infoURL; if (appcastURL != nil) { - _infoURL = [NSURL URLWithString:theInfoURL relativeToURL:appcastURL]; + infoURL = [NSURL URLWithString:theInfoURL relativeToURL:appcastURL]; } else { - _infoURL = [NSURL URLWithString:theInfoURL]; + infoURL = [NSURL URLWithString:theInfoURL]; + } + + if ([infoURL.scheme caseInsensitiveCompare:@"http"] == NSOrderedSame || [infoURL.scheme caseInsensitiveCompare:@"https"] == NSOrderedSame) { + _infoURL = infoURL; + } else { + SULog(SULogLevelError, @"%@ -%@ Info URL must have a http or https URL scheme.", NSStringFromClass([self class]), NSStringFromSelector(_cmd)); } } } @@ -431,10 +438,19 @@ static NSString *SUAppcastItemStateKey = @"SUAppcastItemState"; if (enclosureURLString) { // Sparkle used to always URL-encode, so for backwards compatibility spaces in URLs must be forgiven. NSString *fileURLString = [enclosureURLString stringByReplacingOccurrencesOfString:@" " withString:@"%20"]; + + NSURL *fileURL; if (appcastURL != nil) { - _fileURL = [NSURL URLWithString:fileURLString relativeToURL:appcastURL]; + fileURL = [NSURL URLWithString:fileURLString relativeToURL:appcastURL]; } else { - _fileURL = [NSURL URLWithString:fileURLString]; + fileURL = [NSURL URLWithString:fileURLString]; + } + + if ([fileURL.scheme caseInsensitiveCompare:@"http"] == NSOrderedSame || [fileURL.scheme caseInsensitiveCompare:@"https"] == NSOrderedSame) { + _fileURL = fileURL; + } else { + SULog(SULogLevelError, @"File URLs must have a http or https URL scheme."); + _fileURL = nil; } } if (enclosure) { @@ -540,10 +556,11 @@ static NSString *SUAppcastItemStateKey = @"SUAppcastItemState"; } else { url = [NSURL URLWithString:releaseNotesString]; } - if ([url isFileURL]) { - SULog(SULogLevelError, @"Release notes with file:// URLs are not supported"); - } else { + if ([url.scheme caseInsensitiveCompare:@"http"] == NSOrderedSame || [url.scheme caseInsensitiveCompare:@"https"] == NSOrderedSame) { _releaseNotesURL = url; + } else { + SULog(SULogLevelError, @"Release notes must have a http or https URL scheme."); + _releaseNotesURL = nil; } } else if ([self.itemDescription hasPrefix:@"http://"] || [self.itemDescription hasPrefix:@"https://"]) { // if the description starts with http:// or https:// use that. _releaseNotesURL = [NSURL URLWithString:(NSString * _Nonnull)self.itemDescription]; @@ -554,11 +571,17 @@ static NSString *SUAppcastItemStateKey = @"SUAppcastItemState"; // Get full release notes URL if informed. NSString *fullReleaseNotesString = [dict objectForKey:SUAppcastElementFullReleaseNotesLink]; if (fullReleaseNotesString) { - NSURL *url = [NSURL URLWithString:fullReleaseNotesString]; - if ([url isFileURL]) { - SULog(SULogLevelError, @"Full release notes with file:// URLs are not supported"); + NSURL *url; + if (appcastURL != nil) { + url = [NSURL URLWithString:fullReleaseNotesString relativeToURL:appcastURL]; } else { + url = [NSURL URLWithString:fullReleaseNotesString]; + } + if ([url.scheme caseInsensitiveCompare:@"http"] == NSOrderedSame || [url.scheme caseInsensitiveCompare:@"https"] == NSOrderedSame) { _fullReleaseNotesURL = url; + } else { + SULog(SULogLevelError, @"Full release notes must have a http or https URL scheme."); + _fullReleaseNotesURL = nil; } } else { _fullReleaseNotesURL = nil; diff --git a/TestApplication/sparkletestcast.xml b/TestApplication/sparkletestcast.xml index 77c733af..0e7b95ab 100644 --- a/TestApplication/sparkletestcast.xml +++ b/TestApplication/sparkletestcast.xml @@ -8,6 +8,7 @@ Version 2.0 2.0 https://sparkle-project.org + releasenotes.html diff --git a/Tests/Resources/test-links.xml b/Tests/Resources/test-links.xml new file mode 100644 index 00000000..02d0d96f --- /dev/null +++ b/Tests/Resources/test-links.xml @@ -0,0 +1,30 @@ + + + + For unit test only + + Version 3.0 + Sat, 26 Jul 2014 15:20:12 +0000 + https://sparkle-project.org/notes/relnote-3.0.txt + https://sparkle-project.org/fullnotes.txt + https://sparkle-project.org + + + + Version 2.0 + Sat, 26 Jul 2014 15:20:12 +0000 + http://sparkle-project.org/notes/relnote-2.0.txt + http://sparkle-project.org/fullnotes.txt + http://sparkle-project.org + + + + Version 1.0 + Sat, 26 Jul 2014 15:20:12 +0000 + file://sparkle-project.org/notes/relnote-1.0.txt + file://sparkle-project.org/fullnotes.txt + file://sparkle-project.org + + + + diff --git a/Tests/Resources/test-relative-urls.xml b/Tests/Resources/test-relative-urls.xml index 3b28b920..6eea684a 100644 --- a/Tests/Resources/test-relative-urls.xml +++ b/Tests/Resources/test-relative-urls.xml @@ -15,5 +15,21 @@ 2.0 /info/info-2.0.txt + + Version 1.0 + desc + Sat, 26 Jul 2014 15:20:11 +0000 + 1.0 + notes/fullnotes.txt + + + + Version 0.9 + desc + Sat, 26 Jul 2014 15:20:11 +0000 + 0.9 + https://sparkle-project.org/releasenotes.html + + diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index a4feefab..ed790a56 100644 --- a/Tests/SUAppcastTest.swift +++ b/Tests/SUAppcastTest.swift @@ -644,6 +644,44 @@ class SUAppcastTest: XCTestCase { XCTFail(err.localizedDescription) } } + + func testLinks() { + let testFile = Bundle(for: SUAppcastTest.self).path(forResource: "test-links", ofType: "xml")! + let testData = NSData(contentsOfFile: testFile)! + + do { + let baseURL: URL? = nil + + let stateResolver = SPUAppcastItemStateResolver(hostVersion: "1.0", applicationVersionComparator: SUStandardVersionComparator.default, standardVersionComparator: SUStandardVersionComparator.default) + + let appcast = try SUAppcast(xmlData: testData as Data, relativeTo: baseURL, stateResolver: stateResolver) + let items = appcast.items + + XCTAssertEqual(3, items.count) + + // Test https + XCTAssertEqual("https://sparkle-project.org/notes/relnote-3.0.txt", items[0].releaseNotesURL?.absoluteString) + XCTAssertEqual("https://sparkle-project.org/fullnotes.txt", items[0].fullReleaseNotesURL?.absoluteString) + XCTAssertEqual("https://sparkle-project.org", items[0].infoURL?.absoluteString) + XCTAssertEqual("https://sparkle-project.org/release-3.0.zip", items[0].fileURL?.absoluteString) + + // Test http + XCTAssertEqual("http://sparkle-project.org/notes/relnote-2.0.txt", items[1].releaseNotesURL?.absoluteString) + XCTAssertEqual("http://sparkle-project.org/fullnotes.txt", items[1].fullReleaseNotesURL?.absoluteString) + XCTAssertEqual("http://sparkle-project.org", items[1].infoURL?.absoluteString) + XCTAssertEqual("http://sparkle-project.org/release-2.0.zip", items[1].fileURL?.absoluteString) + + // Test bad file URLs + XCTAssertEqual(nil, items[2].releaseNotesURL?.absoluteString) + XCTAssertEqual(nil, items[2].fullReleaseNotesURL?.absoluteString) + XCTAssertEqual(nil, items[2].infoURL?.absoluteString) + XCTAssertEqual(nil, items[2].fileURL?.absoluteString) + + } catch let err as NSError { + NSLog("%@", err) + XCTFail(err.localizedDescription) + } + } func testRelativeURLs() { let testFile = Bundle(for: SUAppcastTest.self).path(forResource: "test-relative-urls", ofType: "xml")! @@ -657,12 +695,17 @@ class SUAppcastTest: XCTestCase { let appcast = try SUAppcast(xmlData: testData as Data, relativeTo: baseURL, stateResolver: stateResolver) let items = appcast.items - XCTAssertEqual(2, items.count) + XCTAssertEqual(4, items.count) XCTAssertEqual("https://fake.sparkle-project.org/updates/release-3.0.zip", items[0].fileURL?.absoluteString) XCTAssertEqual("https://fake.sparkle-project.org/updates/notes/relnote-3.0.txt", items[0].releaseNotesURL?.absoluteString) XCTAssertEqual("https://fake.sparkle-project.org/info/info-2.0.txt", items[1].infoURL?.absoluteString) + + XCTAssertEqual("https://fake.sparkle-project.org/updates/notes/fullnotes.txt", items[2].fullReleaseNotesURL?.absoluteString) + + // If a different base URL is in the feed, we should respect the base URL in the feed + XCTAssertEqual("https://sparkle-project.org/releasenotes.html", items[3].fullReleaseNotesURL?.absoluteString) } catch let err as NSError { NSLog("%@", err)