diff --git a/.swift-version b/.swift-version index 5186d07..7d5c902 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -4.0 +4.1 diff --git a/Sources/SwiftLinkPreview.swift b/Sources/SwiftLinkPreview.swift index 6c1306b..712578b 100644 --- a/Sources/SwiftLinkPreview.swift +++ b/Sources/SwiftLinkPreview.swift @@ -162,12 +162,12 @@ open class SwiftLinkPreview: NSObject { if let range = absoluteString.range(of: "url="), let lastChar = absoluteString.last, - let lastCharIndex = absoluteString.lastIndex(of: lastChar) { - absoluteString = String(absoluteString[range.upperBound ..< lastCharIndex]) + let lastCharIndex = absoluteString.range(of: String(lastChar), options: .backwards, range: nil, locale: nil) { + absoluteString = String(absoluteString[range.upperBound ..< lastCharIndex.upperBound]) if let range = absoluteString.range(of: "&"), let firstChar = absoluteString.first, - let firstCharIndex = absoluteString.firstIndex(of: firstChar) { + let firstCharIndex = absoluteString.index(of: firstChar) { absoluteString = String(absoluteString[firstCharIndex ..< absoluteString.index(before: range.upperBound)]) if let decoded = absoluteString.removingPercentEncoding, let newURL = URL(string: decoded) { diff --git a/SwiftLinkPreview.xcodeproj/project.pbxproj b/SwiftLinkPreview.xcodeproj/project.pbxproj index cdaee41..89a594f 100644 --- a/SwiftLinkPreview.xcodeproj/project.pbxproj +++ b/SwiftLinkPreview.xcodeproj/project.pbxproj @@ -556,16 +556,16 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = leocardz.com; TargetAttributes = { 98846C951D09AA6E00846726 = { CreatedOnToolsVersion = 7.3; - LastSwiftMigration = 0800; + LastSwiftMigration = 1000; }; 98DC53371D1D73DB001134E3 = { CreatedOnToolsVersion = 7.3; - LastSwiftMigration = 0800; + LastSwiftMigration = 1000; }; 98E7C2F31D3B2300009E5F6D = { CreatedOnToolsVersion = 7.3.1; @@ -845,12 +845,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -905,12 +907,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -965,7 +969,7 @@ SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; VALID_ARCHS = "armv7 arm64 armv7s"; }; name = Debug; @@ -988,7 +992,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; VALID_ARCHS = "armv7 arm64 armv7s"; }; name = Release; @@ -1004,7 +1008,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "SwiftLinkPreviewTests/SwiftLinkPreviewTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -1018,7 +1022,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.leocardz.SwiftLinkPreviewTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "SwiftLinkPreviewTests/SwiftLinkPreviewTests-Bridging-Header.h"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/SwiftLinkPreview.xcodeproj/xcshareddata/xcschemes/SwiftLinkPreview.xcscheme b/SwiftLinkPreview.xcodeproj/xcshareddata/xcschemes/SwiftLinkPreview.xcscheme index 6cfbb64..7e8397b 100644 --- a/SwiftLinkPreview.xcodeproj/xcshareddata/xcschemes/SwiftLinkPreview.xcscheme +++ b/SwiftLinkPreview.xcodeproj/xcshareddata/xcschemes/SwiftLinkPreview.xcscheme @@ -1,6 +1,6 @@ String { - let path = Bundle(for: object_getClass(self)).path(forResource: file, ofType: "html") + let path = Bundle(for: object_getClass(self)!).path(forResource: file, ofType: "html") let fileHtml = try! NSString(contentsOfFile: path!, encoding: String.Encoding.utf8.rawValue) return String(fileHtml) diff --git a/SwiftLinkPreviewTests/IconTests.swift b/SwiftLinkPreviewTests/IconTests.swift index 83b2a79..742884b 100644 --- a/SwiftLinkPreviewTests/IconTests.swift +++ b/SwiftLinkPreviewTests/IconTests.swift @@ -50,9 +50,14 @@ class IconTests: XCTestCase { testTemplate = testTemplate.replace(Constants.href, with: icon) testTemplate = testTemplate.replace(Constants.rel, with: type) - let result = slp.crawIcon(testTemplate, canonicalUrl: "google.com", result: SwiftLinkPreview.Response()) + var result = SwiftLinkPreview.Response() + result[.url] = "google.com" + result[.canonicalUrl] = "google.com" + result[.finalUrl] = URL(string: "https://google.com") - let url = icon.range(of: "http") != nil ? icon : "http://google.com/\(icon)".replace("com//", with: "com/") + result = slp.crawIcon(testTemplate, result: result) + + let url = icon.range(of: "http") != nil ? icon : "https://google.com/\(icon)".replace("com//", with: "com/") XCTAssertEqual(url, result[.icon] as! String) } diff --git a/SwiftLinkPreviewTests/ImageTests.swift b/SwiftLinkPreviewTests/ImageTests.swift index a5e99bc..cfd3414 100644 --- a/SwiftLinkPreviewTests/ImageTests.swift +++ b/SwiftLinkPreviewTests/ImageTests.swift @@ -42,7 +42,7 @@ class ImageTests: XCTestCase { singleImageTemplate = singleImageTemplate.replace(Constants.bodyRandom, with: String.randomTag()).extendedTrim - let result = self.slp.crawlImages(singleImageTemplate, canonicalUrl: nil, result: SwiftLinkPreview.Response()) + let result = self.slp.crawlImages(singleImageTemplate, result: SwiftLinkPreview.Response()) XCTAssertEqual((result[.image] as! String), data[Constants.image]) @@ -78,7 +78,7 @@ class ImageTests: XCTestCase { galleryImageTemplate = galleryImageTemplate.replace(Constants.bodyRandom, with: String.randomTag()).extendedTrim - let result = self.slp.crawlImages(galleryImageTemplate, canonicalUrl: nil, result: SwiftLinkPreview.Response()) + let result = self.slp.crawlImages(galleryImageTemplate, result: SwiftLinkPreview.Response()) XCTAssertEqual((result[.images] as! [String])[0], data[Constants.image1]) XCTAssertEqual((result[.images] as! [String])[1], data[Constants.image2]) diff --git a/SwiftLinkPreviewTests/MemoryLeaks.swift b/SwiftLinkPreviewTests/MemoryLeaks.swift index 3a19b17..48c21d4 100644 --- a/SwiftLinkPreviewTests/MemoryLeaks.swift +++ b/SwiftLinkPreviewTests/MemoryLeaks.swift @@ -46,16 +46,16 @@ class MemoryCheckedSwiftLinkPrefiew : SwiftLinkPreview { class MemoryLeaks: XCTestCase { - func testObjectDestroy() { - let e = expectation(description: "Object") - let requestCount = 3 - let counter = Counter(requestCount) - - for _ in 0..