From d2bf50cc15e70c1b77326666c15af625b3ee5638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Thu, 30 Jul 2020 17:46:00 +0200 Subject: [PATCH 1/4] Prevent crash when passing a remote URL to `Format.of()` --- r2-shared-swift/Format/FormatSnifferContent.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/r2-shared-swift/Format/FormatSnifferContent.swift b/r2-shared-swift/Format/FormatSnifferContent.swift index 47e2a75f..da6740a5 100644 --- a/r2-shared-swift/Format/FormatSnifferContent.swift +++ b/r2-shared-swift/Format/FormatSnifferContent.swift @@ -30,8 +30,11 @@ final class FormatSnifferFileContent: FormatSnifferContent, Loggable { let file: URL - init(file: URL) { - assert(file.isFileURL || file.scheme == nil) + init?(file: URL) { + guard file.isFileURL || file.scheme == nil else { + return nil + } + self.file = file } From 78eb5a26cb31cbe3766b5fd7313fc40838a42a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Mon, 3 Aug 2020 09:35:05 +0200 Subject: [PATCH 2/4] Add URL.addingSchemeIfMissing() --- r2-shared-swift.xcodeproj/project.pbxproj | 16 +++++++++++ r2-shared-swift/Toolkit/Extensions/URL.swift | 27 ++++++++++++++++++ .../Toolkit/Extensions/URLTests.swift | 28 +++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 r2-shared-swift/Toolkit/Extensions/URL.swift create mode 100644 r2-shared-swiftTests/Toolkit/Extensions/URLTests.swift diff --git a/r2-shared-swift.xcodeproj/project.pbxproj b/r2-shared-swift.xcodeproj/project.pbxproj index b0220f02..fbcbb1ac 100644 --- a/r2-shared-swift.xcodeproj/project.pbxproj +++ b/r2-shared-swift.xcodeproj/project.pbxproj @@ -95,6 +95,8 @@ CA9E6BA4223A657900ECF6E4 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA9E6BA3223A657900ECF6E4 /* JSON.swift */; }; CA9E6BA9223A749900ECF6E4 /* Publication+EPUB.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA9E6BA8223A749900ECF6E4 /* Publication+EPUB.swift */; }; CA9E6BAE223A76C600ECF6E4 /* Publication+OPDS.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA9E6BAD223A76C600ECF6E4 /* Publication+OPDS.swift */; }; + CAAABA9D24D7F248004A4466 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAAABA9C24D7F248004A4466 /* URL.swift */; }; + CAAABAA024D7F2DC004A4466 /* URLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAAABA9F24D7F2DC004A4466 /* URLTests.swift */; }; CAAF80CA2456D7370024D7AE /* AudioSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAAF80C92456D7370024D7AE /* AudioSession.swift */; }; CAB88C92224E766E00D36C99 /* LocatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAB88C91224E766E00D36C99 /* LocatorTests.swift */; }; CABBB2E52237ADEB004EB039 /* Feed.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3B1879F1FA33D4D00BB46BF /* Feed.swift */; }; @@ -244,6 +246,8 @@ CA9E6BA6223A67D300ECF6E4 /* Publication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Publication.swift; sourceTree = ""; }; CA9E6BA8223A749900ECF6E4 /* Publication+EPUB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Publication+EPUB.swift"; sourceTree = ""; }; CA9E6BAD223A76C600ECF6E4 /* Publication+OPDS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Publication+OPDS.swift"; sourceTree = ""; }; + CAAABA9C24D7F248004A4466 /* URL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URL.swift; sourceTree = ""; }; + CAAABA9F24D7F2DC004A4466 /* URLTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLTests.swift; sourceTree = ""; }; CAAF80C92456D7370024D7AE /* AudioSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioSession.swift; sourceTree = ""; }; CAB88C91224E766E00D36C99 /* LocatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocatorTests.swift; sourceTree = ""; }; CABBB2F32237BF42004EB039 /* OPDSPriceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OPDSPriceTests.swift; sourceTree = ""; }; @@ -403,6 +407,7 @@ CA252DDE2447A5AE0005067C /* Toolkit */ = { isa = PBXGroup; children = ( + CAAABA9E24D7F2CD004A4466 /* Extensions */, CA252DDF2447A5B40005067C /* Archive */, CA7116EE2455935100C029FD /* DocumentTypesTests.swift */, ); @@ -566,6 +571,7 @@ CA68BDCD24407750009A6BAA /* StringEncoding.swift */, CAD0FEC1244310BB0053C998 /* Array.swift */, CAD1EE6F245AC29B00C1E684 /* String.swift */, + CAAABA9C24D7F248004A4466 /* URL.swift */, ); path = Extensions; sourceTree = ""; @@ -622,6 +628,14 @@ path = OPDS; sourceTree = ""; }; + CAAABA9E24D7F2CD004A4466 /* Extensions */ = { + isa = PBXGroup; + children = ( + CAAABA9F24D7F2DC004A4466 /* URLTests.swift */, + ); + path = Extensions; + sourceTree = ""; + }; CAC34F04221C61BD002C452E /* DRM */ = { isa = PBXGroup; children = ( @@ -854,6 +868,7 @@ CA16A8742233004A00E66255 /* PropertiesTests.swift in Sources */, CA16A8802233BE6900E66255 /* EncryptionTests.swift in Sources */, CA5F8EFB2404142C00926120 /* EPUBLayoutTests.swift in Sources */, + CAAABAA024D7F2DC004A4466 /* URLTests.swift in Sources */, CA6F27742469E4DA0065B405 /* FileFetcherTests.swift in Sources */, CA40C07A21FF25F80069A50E /* JSON.swift in Sources */, CA68BDD12440E123009A6BAA /* FormatSnifferTests.swift in Sources */, @@ -956,6 +971,7 @@ CABBB2E72237ADEB004EB039 /* Facet.swift in Sources */, CA16A8822233FE3200E66255 /* Metadata.swift in Sources */, CA68BDC924406C10009A6BAA /* FormatSniffer.swift in Sources */, + CAAABA9D24D7F248004A4466 /* URL.swift in Sources */, CA3386E12404FAD000FDCBBA /* Encryption.swift in Sources */, CAF4EAE52237ABC700A17DA1 /* MediaOverlays.swift in Sources */, CA3386EE24056ADB00FDCBBA /* Locator+HTML.swift in Sources */, diff --git a/r2-shared-swift/Toolkit/Extensions/URL.swift b/r2-shared-swift/Toolkit/Extensions/URL.swift new file mode 100644 index 00000000..302b1949 --- /dev/null +++ b/r2-shared-swift/Toolkit/Extensions/URL.swift @@ -0,0 +1,27 @@ +// +// URL.swift +// r2-shared-swift +// +// Created by Mickaël Menu on 03/08/2020. +// +// Copyright 2020 Readium Foundation. All rights reserved. +// Use of this source code is governed by a BSD-style license which is detailed +// in the LICENSE file present in the project repository where this source code is maintained. +// + +import Foundation + +extension URL { + + /// Adds the given `newScheme` to the URL, but only if the URL doesn't already have one. + public func addingSchemeIfMissing(_ newScheme: String) -> URL { + guard scheme == nil else { + return self + } + + var components = URLComponents(url: self, resolvingAgainstBaseURL: true) + components?.scheme = newScheme + return components?.url ?? self + } + +} diff --git a/r2-shared-swiftTests/Toolkit/Extensions/URLTests.swift b/r2-shared-swiftTests/Toolkit/Extensions/URLTests.swift new file mode 100644 index 00000000..d672623a --- /dev/null +++ b/r2-shared-swiftTests/Toolkit/Extensions/URLTests.swift @@ -0,0 +1,28 @@ +// +// URLTests.swift +// r2-shared-swift +// +// Created by Mickaël Menu on 03/08/2020. +// +// Copyright 2020 Readium Foundation. All rights reserved. +// Use of this source code is governed by a BSD-style license which is detailed +// in the LICENSE file present in the project repository where this source code is maintained. +// + +import XCTest +@testable import R2Shared + +class URLTests: XCTestCase { + + func testAddingSchemeIfMissing() { + XCTAssertEqual( + URL(string: "//www.google.com/path")!.addingSchemeIfMissing("test"), + URL(string: "test://www.google.com/path")! + ) + XCTAssertEqual( + URL(string: "http://www.google.com/path")!.addingSchemeIfMissing("test"), + URL(string: "http://www.google.com/path")! + ) + } + +} From c582cdd808a3612caa64f437120281b1379ae1ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Tue, 11 Aug 2020 11:23:51 +0200 Subject: [PATCH 3/4] Bump version to 2.0.0-alpha.1 --- .github/CODEOWNERS | 1 - CHANGELOG.md | 4 +++- R2Shared.podspec | 4 ++-- README.md | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) delete mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS deleted file mode 100644 index d9ce658a..00000000 --- a/.github/CODEOWNERS +++ /dev/null @@ -1 +0,0 @@ -* @aferditamuriqi diff --git a/CHANGELOG.md b/CHANGELOG.md index 455fd175..3373172a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +## [2.0.0-alpha.1] + ### Added * The new [Format API](https://github.com/readium/architecture/blob/master/proposals/001-format-api.md) simplifies the detection of file formats, including known publication formats such as EPUB and PDF. @@ -27,4 +29,4 @@ All notable changes to this project will be documented in this file. * Dependencies to format-related third-party libraries such as ZIP, XML and PDF are being consolidated into `r2-shared-swift`. Therefore, `r2-shared-swift` now depends on Fuzi and ZIPFoundation. This change will improve maintainability by isolating third-party code and allow (work in progress) to substitute the default libraries with custom ones. [unreleased]: https://github.com/readium/r2-shared-swift/compare/master...HEAD -[x.x.x]: https://github.com/readium/r2-shared-swift/compare/1.4.3...x.x.x +[2.0.0-alpha.1]: https://github.com/readium/r2-shared-swift/compare/1.4.3...2.0.0-alpha.1 diff --git a/R2Shared.podspec b/R2Shared.podspec index e60df9b6..9d592f7a 100644 --- a/R2Shared.podspec +++ b/R2Shared.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |s| s.name = 'R2Shared' - s.version = '1.4.3' + s.version = '2.0.0-alpha.1' s.license = 'BSD 3-Clause License' s.summary = 'R2 Shared' s.homepage = 'http://readium.github.io' s.author = { "Aferdita Muriqi" => "aferdita.muriqi@gmail.com" } - s.source = { :git => 'https://github.com/readium/r2-shared-swift.git', :tag => '1.4.3' } + s.source = { :git => 'https://github.com/readium/r2-shared-swift.git', :tag => '2.0.0-alpha.1' } s.exclude_files = ["**/Info*.plist"] s.requires_arc = true s.resources = ['r2-shared-swift/Resources/**'] diff --git a/README.md b/README.md index 1e38a3e7..92645e4d 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ install R2Shared with Carthage: 2. Update your Cartfile to include the following: ```ruby - github "readium/r2-shared-swift" ~> 1.2.7 + github "readium/r2-shared-swift" "develop" ``` 3. Run `carthage update` and @@ -52,7 +52,7 @@ R2Shared with CocoaPods: use_frameworks! target 'YourAppTargetName' do - pod 'R2Shared', :git => 'https://github.com/readium/r2-shared-swift.git', '~> 1.2.7' + pod 'R2Shared', :git => 'https://github.com/readium/r2-shared-swift.git', :branch => 'develop' end ``` From c77b663dfed7e8e0d9317c7c01daaccb878bf9fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Tue, 11 Aug 2020 12:19:53 +0200 Subject: [PATCH 4/4] Update Travis configuration and add libxml2 dependency --- .travis.yml | 2 ++ R2Shared.podspec | 4 +++- r2-shared-swift.xcodeproj/project.pbxproj | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index abc361fc..10c90582 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,8 @@ cache: before_install: - brew update + - brew outdated carthage || brew upgrade carthage + - carthage bootstrap --verbose --no-use-binaries --platform iOS --cache-builds script: - xcodebuild clean build -quiet diff --git a/R2Shared.podspec b/R2Shared.podspec index 9d592f7a..74251afb 100644 --- a/R2Shared.podspec +++ b/R2Shared.podspec @@ -7,13 +7,15 @@ Pod::Spec.new do |s| s.homepage = 'http://readium.github.io' s.author = { "Aferdita Muriqi" => "aferdita.muriqi@gmail.com" } s.source = { :git => 'https://github.com/readium/r2-shared-swift.git', :tag => '2.0.0-alpha.1' } - s.exclude_files = ["**/Info*.plist"] + s.exclude_files = ["**/Info*.plist", "r2-shared-swift/Toolkit/Archive/ZIPFoundation.swift"] s.requires_arc = true s.resources = ['r2-shared-swift/Resources/**'] s.source_files = "r2-shared-swift/**/*.{m,h,swift}" s.platform = :ios s.ios.deployment_target = "10.0" s.frameworks = 'CoreServices' + s.libraries = 'xml2' + s.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(SDKROOT)/usr/include/libxml2' } s.dependency 'Fuzi' s.dependency 'Minizip' diff --git a/r2-shared-swift.xcodeproj/project.pbxproj b/r2-shared-swift.xcodeproj/project.pbxproj index fbcbb1ac..2ad79836 100644 --- a/r2-shared-swift.xcodeproj/project.pbxproj +++ b/r2-shared-swift.xcodeproj/project.pbxproj @@ -1196,10 +1196,12 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", ); + HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2"; INFOPLIST_FILE = "r2-shared-swift/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + OTHER_LDFLAGS = "-lxml2"; PRODUCT_BUNDLE_IDENTIFIER = "org.readium.r2-shared-swift"; PRODUCT_NAME = R2Shared; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1228,10 +1230,12 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", ); + HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2"; INFOPLIST_FILE = "r2-shared-swift/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + OTHER_LDFLAGS = "-lxml2"; PRODUCT_BUNDLE_IDENTIFIER = "org.readium.r2-shared-swift"; PRODUCT_NAME = R2Shared; PROVISIONING_PROFILE_SPECIFIER = "";