From dccf8ef19bd0a761a0464023014965b181f0b847 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 16 Apr 2024 14:34:09 +1000 Subject: [PATCH 01/17] DRY `env` and `agents` in Buildkite pipeline --- .buildkite/pipeline.yml | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index a2cbd010f..0e430efc0 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -2,9 +2,11 @@ common_params: plugins: &common_plugins - automattic/a8c-ci-toolkit#3.3.0 - # Common environment values to use with the `env` key. - env: &common_env - IMAGE_ID: xcode-13 + +agents: + queue: mac +env: + IMAGE_ID: xcode-13 # This is the default pipeline – it will build and test the app steps: @@ -15,7 +17,6 @@ steps: key: "test" command: | build_and_test_pod - env: *common_env plugins: *common_plugins ################# @@ -25,7 +26,6 @@ steps: key: "validate" command: | validate_podspec - env: *common_env plugins: *common_plugins ################# @@ -35,7 +35,6 @@ steps: key: "lint" command: | lint_pod - env: *common_env plugins: *common_plugins ################# @@ -44,15 +43,12 @@ steps: - label: "⬆️ Publish Aztec Podspec" key: "publish-aztec" command: .buildkite/publish-aztec-pod.sh - env: *common_env plugins: *common_plugins depends_on: - "test" - "validate" - "lint" if: build.tag != null - agents: - queue: "mac" ################# # Publish the Podspec (if we're building a tag) @@ -60,12 +56,9 @@ steps: - label: "⬆️ Publish Editor Podspec" key: "publish-editor" command: .buildkite/publish-editor-pod.sh - env: *common_env plugins: *common_plugins depends_on: - "test" - "validate" - "lint" if: build.tag != null - agents: - queue: "mac" From afc4064ad24cb71ef5463c87a55a1bdfb9fc4046 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 16 Apr 2024 14:35:15 +1000 Subject: [PATCH 02/17] Address an access control warning > Non-'@objc' instance method in extensions cannot be overridden; > use 'public' instead --- Aztec/Classes/Extensions/NSAttributedString+Attachments.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aztec/Classes/Extensions/NSAttributedString+Attachments.swift b/Aztec/Classes/Extensions/NSAttributedString+Attachments.swift index 7a16287b9..a8ebf88ed 100644 --- a/Aztec/Classes/Extensions/NSAttributedString+Attachments.swift +++ b/Aztec/Classes/Extensions/NSAttributedString+Attachments.swift @@ -100,7 +100,7 @@ extension NSAttributedString // MARK: - Captions - open func caption(for attachment: NSTextAttachment) -> NSAttributedString? { + public func caption(for attachment: NSTextAttachment) -> NSAttributedString? { guard let captionRange = self.captionRange(for: attachment) else { return nil } From 168f40e67dd41c6f06c9289d080d00d388d12d8d Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 16 Apr 2024 14:37:20 +1000 Subject: [PATCH 03/17] Centralize deployment target definition at projects level --- Aztec.xcodeproj/project.pbxproj | 4 ---- WordPressEditor/WordPressEditor.xcodeproj/project.pbxproj | 3 --- 2 files changed, 7 deletions(-) diff --git a/Aztec.xcodeproj/project.pbxproj b/Aztec.xcodeproj/project.pbxproj index a76e24ede..d0877ea99 100644 --- a/Aztec.xcodeproj/project.pbxproj +++ b/Aztec.xcodeproj/project.pbxproj @@ -1926,7 +1926,6 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Aztec/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MARKETING_VERSION = 1.15.0; PRODUCT_BUNDLE_IDENTIFIER = org.wordpress.Aztec; @@ -1953,7 +1952,6 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Aztec/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MARKETING_VERSION = 1.15.0; PRODUCT_BUNDLE_IDENTIFIER = org.wordpress.Aztec; @@ -2070,7 +2068,6 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Aztec/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MARKETING_VERSION = 1.15.0; PRODUCT_BUNDLE_IDENTIFIER = org.wordpress.Aztec; @@ -2178,7 +2175,6 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Aztec/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MARKETING_VERSION = 1.15.0; PRODUCT_BUNDLE_IDENTIFIER = org.wordpress.Aztec; diff --git a/WordPressEditor/WordPressEditor.xcodeproj/project.pbxproj b/WordPressEditor/WordPressEditor.xcodeproj/project.pbxproj index b13f3dcb5..5291c145b 100644 --- a/WordPressEditor/WordPressEditor.xcodeproj/project.pbxproj +++ b/WordPressEditor/WordPressEditor.xcodeproj/project.pbxproj @@ -789,7 +789,6 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = WordPressEditor/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -962,7 +961,6 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = WordPressEditor/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -990,7 +988,6 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = WordPressEditor/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", From 2f50d83de2c2d6d2c9f6ed7f9ec73eb0fa9d3e4e Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 16 Apr 2024 14:38:22 +1000 Subject: [PATCH 04/17] Bump deployment target to iOS 12.0, minimum for Xcode 15.3 --- Aztec.xcodeproj/project.pbxproj | 8 ++++---- WordPress-Aztec-iOS.podspec | 2 +- WordPress-Editor-iOS.podspec | 2 +- WordPressEditor/WordPressEditor.xcodeproj/project.pbxproj | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Aztec.xcodeproj/project.pbxproj b/Aztec.xcodeproj/project.pbxproj index d0877ea99..fd1cc5ef3 100644 --- a/Aztec.xcodeproj/project.pbxproj +++ b/Aztec.xcodeproj/project.pbxproj @@ -1836,7 +1836,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = /usr/include/libxml2; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = "-lxml2"; @@ -1898,7 +1898,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = /usr/include/libxml2; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; OTHER_LDFLAGS = "-lxml2"; SDKROOT = iphoneos; @@ -2040,7 +2040,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = /usr/include/libxml2; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = "-lxml2"; @@ -2146,7 +2146,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = /usr/include/libxml2; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = "-lxml2"; diff --git a/WordPress-Aztec-iOS.podspec b/WordPress-Aztec-iOS.podspec index 48255db3b..b98633e7f 100644 --- a/WordPress-Aztec-iOS.podspec +++ b/WordPress-Aztec-iOS.podspec @@ -15,7 +15,7 @@ Pod::Spec.new do |s| s.license = { type: 'MPLv2', file: 'LICENSE.md' } s.author = { 'The WordPress Mobile Team' => 'mobile@wordpress.org' } - s.ios.deployment_target = '11.0' + s.ios.deployment_target = '12.0' s.swift_version = '5.0' s.source = { git: 'https://github.com/wordpress-mobile/AztecEditor-iOS.git', tag: s.version.to_s } diff --git a/WordPress-Editor-iOS.podspec b/WordPress-Editor-iOS.podspec index 9a29b2618..d074f64e7 100644 --- a/WordPress-Editor-iOS.podspec +++ b/WordPress-Editor-iOS.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| s.license = { type: 'MPLv2', file: 'LICENSE.md' } s.author = { 'The WordPress Mobile Team' => 'mobile@wordpress.org' } - s.ios.deployment_target = '11.0' + s.ios.deployment_target = '12.0' s.swift_version = '5.0' s.source = { git: 'https://github.com/wordpress-mobile/AztecEditor-iOS.git', tag: s.version.to_s } diff --git a/WordPressEditor/WordPressEditor.xcodeproj/project.pbxproj b/WordPressEditor/WordPressEditor.xcodeproj/project.pbxproj index 5291c145b..ccc474ecf 100644 --- a/WordPressEditor/WordPressEditor.xcodeproj/project.pbxproj +++ b/WordPressEditor/WordPressEditor.xcodeproj/project.pbxproj @@ -763,7 +763,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -875,7 +875,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -935,7 +935,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_COMPILATION_MODE = wholemodule; From 380e6acd5aadf10441351c240e8e153ddeebf7e7 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 16 Apr 2024 14:45:33 +1000 Subject: [PATCH 05/17] Use Xcode 15.3 in CI --- .buildkite/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 0e430efc0..f44dfe413 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -6,7 +6,7 @@ common_params: agents: queue: mac env: - IMAGE_ID: xcode-13 + IMAGE_ID: xcode-15.3-v3 # This is the default pipeline – it will build and test the app steps: From 0b5918066c6fa52608486c554686117a0d42378b Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 16 Apr 2024 15:53:52 +1000 Subject: [PATCH 06/17] Use Ruby 3.2.2 and update RuboCop to compatible version --- .ruby-version | 2 +- Gemfile.lock | 31 ++++++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.ruby-version b/.ruby-version index a4dd9dba4..be94e6f53 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.4 +3.2.2 diff --git a/Gemfile.lock b/Gemfile.lock index a6f7a23ca..8c9c6acad 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -206,6 +206,7 @@ GEM jmespath (1.5.0) json (2.6.1) jwt (2.3.0) + language_server-protocol (3.17.0.3) memoist (0.16.2) mini_magick (4.11.0) mini_mime (1.1.2) @@ -219,34 +220,38 @@ GEM netrc (0.11.0) optparse (0.1.1) os (1.1.4) - parallel (1.21.0) - parser (3.1.0.0) + parallel (1.24.0) + parser (3.3.0.5) ast (~> 2.4.1) + racc plist (3.6.0) public_suffix (4.0.6) + racc (1.7.3) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.2.0) + regexp_parser (2.9.0) representable (3.1.1) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) uber (< 0.2.0) retriable (3.1.2) - rexml (3.2.5) + rexml (3.2.6) rouge (2.0.7) - rubocop (1.25.1) + rubocop (1.63.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.1.0.0) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.15.1, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.15.1) - parser (>= 3.0.1.1) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.2) + parser (>= 3.3.0.4) ruby-macho (2.5.1) - ruby-progressbar (1.11.0) + ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) rubyzip (2.3.2) security (0.1.3) @@ -273,7 +278,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.8) - unicode-display_width (2.1.0) + unicode-display_width (2.5.0) webrick (1.7.0) word_wrap (1.0.0) xcodeproj (1.21.0) From 34808d7c5cc7c4e3afef9500a6549f216f8c4c20 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 16 Apr 2024 15:57:04 +1000 Subject: [PATCH 07/17] Bump iOS and Simulator versions for CI --- fastlane/Fastfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 252f581a6..db4b4a078 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -2,8 +2,8 @@ default_platform(:ios) -TEST_RUNTIME = 'iOS 15.0' -TEST_DEVICE = 'iPhone 11' +TEST_RUNTIME = 'iOS 17.4' +TEST_DEVICE = 'iPhone 15' platform :ios do desc 'Builds the project and runs tests' From 5baf0b93cbef734bf33eee4b0a6d4383c61927da Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 16 Apr 2024 16:05:09 +1000 Subject: [PATCH 08/17] Allow warnings when validating podspec Ideally, this should be removed once the warnings have been addressed --- .buildkite/pipeline.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index f44dfe413..0e594e94a 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -24,8 +24,9 @@ steps: ################# - label: "🔬 Validate Podspecs" key: "validate" + # Ideally, --allow-warnings should be removed once the warnings have been addressed command: | - validate_podspec + validate_podspec --allow-warnings plugins: *common_plugins ################# From 78bd1177a98bb338264a7e15857df23bf38fcdc0 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 16 Apr 2024 16:39:46 +1000 Subject: [PATCH 09/17] Update Fastlane in the hope it helps with stuck tests in CI --- Gemfile.lock | 154 +++++++++++++++++++++++++-------------------------- 1 file changed, 77 insertions(+), 77 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8c9c6acad..6208c46d9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,38 +1,41 @@ GEM remote: https://rubygems.org/ specs: - CFPropertyList (3.0.5) + CFPropertyList (3.0.7) + base64 + nkf rexml activesupport (7.0.8) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) + addressable (2.8.6) + public_suffix (>= 2.0.2, < 6.0) algoliasearch (1.27.5) httpclient (~> 2.8, >= 2.8.3) json (>= 1.5.1) - artifactory (3.0.15) + artifactory (3.0.17) ast (2.4.2) atomos (0.1.3) - aws-eventstream (1.2.0) - aws-partitions (1.552.0) - aws-sdk-core (3.126.0) - aws-eventstream (~> 1, >= 1.0.2) - aws-partitions (~> 1, >= 1.525.0) - aws-sigv4 (~> 1.1) - jmespath (~> 1.0) - aws-sdk-kms (1.54.0) - aws-sdk-core (~> 3, >= 3.126.0) + aws-eventstream (1.3.0) + aws-partitions (1.913.0) + aws-sdk-core (3.191.6) + aws-eventstream (~> 1, >= 1.3.0) + aws-partitions (~> 1, >= 1.651.0) + aws-sigv4 (~> 1.8) + jmespath (~> 1, >= 1.6.1) + aws-sdk-kms (1.79.0) + aws-sdk-core (~> 3, >= 3.191.0) aws-sigv4 (~> 1.1) - aws-sdk-s3 (1.112.0) - aws-sdk-core (~> 3, >= 3.126.0) + aws-sdk-s3 (1.146.1) + aws-sdk-core (~> 3, >= 3.191.0) aws-sdk-kms (~> 1) - aws-sigv4 (~> 1.4) - aws-sigv4 (1.4.0) + aws-sigv4 (~> 1.8) + aws-sigv4 (1.8.0) aws-eventstream (~> 1, >= 1.0.2) babosa (1.0.4) + base64 (0.2.0) claide (1.1.0) cocoapods (1.12.1) addressable (~> 2.8) @@ -77,17 +80,16 @@ GEM highline (~> 2.0.0) concurrent-ruby (1.2.2) declarative (0.0.20) - digest-crc (0.6.4) + digest-crc (0.6.5) rake (>= 12.0.0, < 14.0.0) - domain_name (0.5.20190701) - unf (>= 0.0.5, < 1.0.0) - dotenv (2.7.6) + domain_name (0.6.20240107) + dotenv (2.8.1) emoji_regex (3.2.3) escape (0.0.4) ethon (0.16.0) ffi (>= 1.15.0) - excon (0.91.0) - faraday (1.9.3) + excon (0.110.0) + faraday (1.10.3) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) faraday-excon (~> 1.1) @@ -106,8 +108,8 @@ GEM faraday-em_synchrony (1.0.0) faraday-excon (1.1.0) faraday-httpclient (1.0.1) - faraday-multipart (1.0.3) - multipart-post (>= 1.2, < 3) + faraday-multipart (1.0.4) + multipart-post (~> 2) faraday-net_http (1.0.1) faraday-net_http_persistent (1.2.0) faraday-patron (1.0.0) @@ -115,15 +117,15 @@ GEM faraday-retry (1.0.3) faraday_middleware (1.2.0) faraday (~> 1.0) - fastimage (2.2.6) - fastlane (2.204.2) + fastimage (2.3.1) + fastlane (2.220.0) CFPropertyList (>= 2.3, < 4.0.0) addressable (>= 2.8, < 3.0.0) artifactory (~> 3.0) aws-sdk-s3 (~> 1.0) babosa (>= 1.0.3, < 2.0.0) bundler (>= 1.12.0, < 3.0.0) - colored + colored (~> 1.2) commander (~> 4.6) dotenv (>= 2.1.1, < 3.0.0) emoji_regex (>= 0.1, < 4.0) @@ -135,33 +137,35 @@ GEM gh_inspector (>= 1.1.2, < 2.0.0) google-apis-androidpublisher_v3 (~> 0.3) google-apis-playcustomapp_v1 (~> 0.1) + google-cloud-env (>= 1.6.0, < 2.0.0) google-cloud-storage (~> 1.31) highline (~> 2.0) + http-cookie (~> 1.0.5) json (< 3.0.0) jwt (>= 2.1.0, < 3) mini_magick (>= 4.9.4, < 5.0.0) - multipart-post (~> 2.0.0) + multipart-post (>= 2.0.0, < 3.0.0) naturally (~> 2.2) - optparse (~> 0.1.1) + optparse (>= 0.1.1, < 1.0.0) plist (>= 3.1.0, < 4.0.0) rubyzip (>= 2.0.0, < 3.0.0) - security (= 0.1.3) + security (= 0.1.5) simctl (~> 1.6.3) terminal-notifier (>= 2.0.0, < 3.0.0) - terminal-table (>= 1.4.5, < 2.0.0) + terminal-table (~> 3) tty-screen (>= 0.6.3, < 1.0.0) tty-spinner (>= 0.8.0, < 1.0.0) word_wrap (~> 1.0.0) xcodeproj (>= 1.13.0, < 2.0.0) xcpretty (~> 0.3.0) - xcpretty-travis-formatter (>= 0.0.3) + xcpretty-travis-formatter (>= 0.0.3, < 2.0.0) ffi (1.15.5) fourflusher (2.3.1) fuzzy_match (2.0.4) gh_inspector (1.1.3) - google-apis-androidpublisher_v3 (0.16.0) - google-apis-core (>= 0.4, < 2.a) - google-apis-core (0.4.2) + google-apis-androidpublisher_v3 (0.54.0) + google-apis-core (>= 0.11.0, < 2.a) + google-apis-core (0.11.3) addressable (~> 2.5, >= 2.5.1) googleauth (>= 0.16.2, < 2.a) httpclient (>= 2.8.1, < 3.a) @@ -169,68 +173,67 @@ GEM representable (~> 3.0) retriable (>= 2.0, < 4.a) rexml - webrick - google-apis-iamcredentials_v1 (0.10.0) - google-apis-core (>= 0.4, < 2.a) - google-apis-playcustomapp_v1 (0.7.0) - google-apis-core (>= 0.4, < 2.a) - google-apis-storage_v1 (0.11.0) - google-apis-core (>= 0.4, < 2.a) - google-cloud-core (1.6.0) - google-cloud-env (~> 1.0) + google-apis-iamcredentials_v1 (0.17.0) + google-apis-core (>= 0.11.0, < 2.a) + google-apis-playcustomapp_v1 (0.13.0) + google-apis-core (>= 0.11.0, < 2.a) + google-apis-storage_v1 (0.31.0) + google-apis-core (>= 0.11.0, < 2.a) + google-cloud-core (1.7.0) + google-cloud-env (>= 1.0, < 3.a) google-cloud-errors (~> 1.0) - google-cloud-env (1.5.0) - faraday (>= 0.17.3, < 2.0) - google-cloud-errors (1.2.0) - google-cloud-storage (1.36.0) + google-cloud-env (1.6.0) + faraday (>= 0.17.3, < 3.0) + google-cloud-errors (1.4.0) + google-cloud-storage (1.47.0) addressable (~> 2.8) digest-crc (~> 0.4) google-apis-iamcredentials_v1 (~> 0.1) - google-apis-storage_v1 (~> 0.1) + google-apis-storage_v1 (~> 0.31.0) google-cloud-core (~> 1.6) googleauth (>= 0.16.2, < 2.a) mini_mime (~> 1.0) - googleauth (1.1.0) - faraday (>= 0.17.3, < 2.0) + googleauth (1.8.1) + faraday (>= 0.17.3, < 3.a) jwt (>= 1.4, < 3.0) - memoist (~> 0.16) multi_json (~> 1.11) os (>= 0.9, < 2.0) signet (>= 0.16, < 2.a) highline (2.0.3) - http-cookie (1.0.4) + http-cookie (1.0.5) domain_name (~> 0.5) httpclient (2.8.3) i18n (1.14.1) concurrent-ruby (~> 1.0) - jmespath (1.5.0) - json (2.6.1) - jwt (2.3.0) + jmespath (1.6.2) + json (2.7.2) + jwt (2.8.1) + base64 language_server-protocol (3.17.0.3) - memoist (0.16.2) - mini_magick (4.11.0) - mini_mime (1.1.2) + mini_magick (4.12.0) + mini_mime (1.1.5) minitest (5.20.0) molinillo (0.8.0) multi_json (1.15.0) - multipart-post (2.0.0) + multipart-post (2.4.0) nanaimo (0.3.0) nap (1.1.0) naturally (2.2.1) netrc (0.11.0) - optparse (0.1.1) + nkf (0.2.0) + optparse (0.5.0) os (1.1.4) parallel (1.24.0) parser (3.3.0.5) ast (~> 2.4.1) racc - plist (3.6.0) - public_suffix (4.0.6) + plist (3.7.1) + public_suffix (4.0.7) racc (1.7.3) rainbow (3.1.1) - rake (13.0.6) + rake (13.2.1) regexp_parser (2.9.0) - representable (3.1.1) + representable (3.2.0) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) uber (< 0.2.0) @@ -254,20 +257,21 @@ GEM ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) rubyzip (2.3.2) - security (0.1.3) - signet (0.16.0) + security (0.1.5) + signet (0.19.0) addressable (~> 2.8) - faraday (>= 0.17.3, < 2.0) + faraday (>= 0.17.5, < 3.a) jwt (>= 1.5, < 3.0) multi_json (~> 1.10) - simctl (1.6.8) + simctl (1.6.10) CFPropertyList naturally terminal-notifier (2.0.0) - terminal-table (1.6.0) + terminal-table (3.0.2) + unicode-display_width (>= 1.1.1, < 3) trailblazer-option (0.1.2) tty-cursor (0.7.1) - tty-screen (0.8.1) + tty-screen (0.8.2) tty-spinner (0.9.3) tty-cursor (~> 0.7) typhoeus (1.4.0) @@ -275,13 +279,9 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) uber (0.1.0) - unf (0.1.4) - unf_ext - unf_ext (0.0.8) unicode-display_width (2.5.0) - webrick (1.7.0) word_wrap (1.0.0) - xcodeproj (1.21.0) + xcodeproj (1.24.0) CFPropertyList (>= 2.3.3, < 4.0) atomos (~> 0.1.3) claide (>= 1.0.2, < 2.0) From e41da8f492950930246fdc93f9f38b5c2159a869 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 16 Apr 2024 16:44:43 +1000 Subject: [PATCH 10/17] Don't waste time cleaning up Simulators in CI --- fastlane/Fastfile | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/fastlane/Fastfile b/fastlane/Fastfile index db4b4a078..258f9694f 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -8,29 +8,23 @@ TEST_DEVICE = 'iPhone 15' platform :ios do desc 'Builds the project and runs tests' lane :test do - device = create_simulator(TEST_RUNTIME, TEST_DEVICE) + # Don't waste time managing Simulators in CI + device = create_simulator(TEST_RUNTIME, TEST_DEVICE) unless is_ci - run_tests( + shared_options = { workspace: 'Aztec.xcworkspace', - scheme: 'Aztec', - device: device.name, prelaunch_simulator: true, buildlog_path: File.join(__dir__, '.build', 'logs'), derived_data_path: File.join(__dir__, '.build', 'derived-data'), ensure_devices_found: true - ) + } - run_tests( - workspace: 'Aztec.xcworkspace', - scheme: 'WordPressEditor', - device: device.name, - prelaunch_simulator: true, - buildlog_path: File.join(__dir__, '.build', 'logs'), - derived_data_path: File.join(__dir__, '.build', 'derived-data'), - ensure_devices_found: true - ) + shared_options[:device] = device.name unless is_ci + + run_tests(**shared_options, scheme: 'Aztec') + run_tests(**shared_options, scheme: 'WordPressEditor') - destroy_simulator(device) + destroy_simulator(device) unless is_ci end end From 665b15bd56ad4a0331c13f71045d693613486362 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Thu, 18 Apr 2024 13:12:35 +0200 Subject: [PATCH 11/17] Fix NSSecureCoding implementations @mokagio This should fix the `testPaste{Image,Video}WithoutFormatting` test failures. - I have searched the code for `decodeObject(forKey` occurrences and confirmed there wasn't any left - But I have not triple-checked that *every* custom subclass of anything we might encode in our `NSAttributedString` attributes have had `+supportsSecureCoding` redefined Indeed, apparently, **even if** the parent class already overrides it to return `true`, subclasses which override `init?(coder:)`/`encode(with:)` from their parent class need to also re-override `+supportsSecureCoding`. I've added the overrides in classes that I've modified, but there may be more classes that might not be covered by our unit tests around archiving/pasting but would still require it to be added? So would be worth making another pass to be sure we didn't forget any, --- Aztec/Classes/EditorView/EditorView.swift | 4 +-- .../NSAttributedString+Archive.swift | 2 +- .../Classes/Libxml2/DOM/Data/Attribute.swift | 12 ++++--- .../Attributes/HTMLRepresentation.swift | 32 +++++++++++++------ .../Attributes/UnsupportedHTML.swift | 14 ++++++-- Aztec/Classes/TextKit/CommentAttachment.swift | 6 ++-- Aztec/Classes/TextKit/HTMLAttachment.swift | 9 +++--- Aztec/Classes/TextKit/ImageAttachment.swift | 2 ++ Aztec/Classes/TextKit/MediaAttachment.swift | 6 ++-- .../ParagraphProperty/Blockquote.swift | 2 ++ .../ParagraphProperty/Figcaption.swift | 4 ++- .../TextKit/ParagraphProperty/Figure.swift | 4 ++- .../TextKit/ParagraphProperty/HTMLDiv.swift | 2 ++ .../TextKit/ParagraphProperty/HTMLLi.swift | 2 ++ .../ParagraphProperty/HTMLParagraph.swift | 2 ++ .../TextKit/ParagraphProperty/HTMLPre.swift | 2 ++ .../TextKit/ParagraphProperty/Header.swift | 2 ++ .../ParagraphProperty/ParagraphProperty.swift | 4 ++- .../TextKit/ParagraphProperty/TextList.swift | 2 ++ Aztec/Classes/TextKit/ParagraphStyle.swift | 11 ++++++- Aztec/Classes/TextKit/VideoAttachment.swift | 4 ++- .../TextKit/HTMLRepresentationTests.swift | 22 ++++++------- AztecTests/TextKit/UnsupportedHTMLTests.swift | 6 ++-- .../Gutenberg/Gutenblock.swift | 3 ++ .../Gutenberg/GutenpackAttachment.swift | 8 ++--- 25 files changed, 113 insertions(+), 54 deletions(-) diff --git a/Aztec/Classes/EditorView/EditorView.swift b/Aztec/Classes/EditorView/EditorView.swift index 959f9724f..1328d6b96 100644 --- a/Aztec/Classes/EditorView/EditorView.swift +++ b/Aztec/Classes/EditorView/EditorView.swift @@ -99,8 +99,8 @@ public class EditorView: UIView { // MARK: - Initializers public required init?(coder aDecoder: NSCoder) { - guard let htmlTextView = aDecoder.decodeObject(forKey: EditorView.htmlTextViewKey) as? UITextView, - let richTextView = aDecoder.decodeObject(forKey: EditorView.richTextViewKey) as? TextView else { + guard let htmlTextView = aDecoder.decodeObject(of: UITextView.self, forKey: EditorView.htmlTextViewKey), + let richTextView = aDecoder.decodeObject(of: TextView.self, forKey: EditorView.richTextViewKey) else { return nil } diff --git a/Aztec/Classes/Extensions/NSAttributedString+Archive.swift b/Aztec/Classes/Extensions/NSAttributedString+Archive.swift index cb0014ba9..81997e2e1 100644 --- a/Aztec/Classes/Extensions/NSAttributedString+Archive.swift +++ b/Aztec/Classes/Extensions/NSAttributedString+Archive.swift @@ -11,7 +11,7 @@ extension NSAttributedString } static func unarchive(with data: Data) throws -> NSAttributedString? { - return try NSKeyedUnarchiver.unarchivedObject(ofClass: NSAttributedString.self, from: data) + return try NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSAttributedString.self, HTMLRepresentation.self], from: data) as? NSAttributedString } } diff --git a/Aztec/Classes/Libxml2/DOM/Data/Attribute.swift b/Aztec/Classes/Libxml2/DOM/Data/Attribute.swift index 7016a903d..ef50ef97f 100644 --- a/Aztec/Classes/Libxml2/DOM/Data/Attribute.swift +++ b/Aztec/Classes/Libxml2/DOM/Data/Attribute.swift @@ -3,7 +3,7 @@ import Foundation /// Represents a basic attribute with no value. This is also the base class for all other /// attributes. /// -public class Attribute: NSObject, CustomReflectable, NSCoding { +public class Attribute: NSObject, CustomReflectable, NSSecureCoding { // MARK: - Attribute Definition Properties @@ -52,15 +52,15 @@ public class Attribute: NSObject, CustomReflectable, NSCoding { public required convenience init?(coder aDecoder: NSCoder) { // TODO: This is a Work in Progress. Let's also get Attribute conforming to Codable! - guard let name = aDecoder.decodeObject(forKey: Keys.name) as? String, - let rawValue = aDecoder.decodeObject(forKey: Keys.value) as? Data, - let value = try? JSONDecoder().decode(Value.self, from: rawValue) else + guard let name = aDecoder.decodeObject(of: NSString.self, forKey: Keys.name), + let rawValue = aDecoder.decodeObject(of: NSData.self, forKey: Keys.value), + let value = try? JSONDecoder().decode(Value.self, from: rawValue as Data) else { assertionFailure("Review the logic.") return nil } - self.init(name: name, value: value) + self.init(name: name as String, value: value) } open func encode(with aCoder: NSCoder) { @@ -72,6 +72,8 @@ public class Attribute: NSObject, CustomReflectable, NSCoding { } } + public class var supportsSecureCoding: Bool { true } + // MARK: - Equatable public override func isEqual(_ object: Any?) -> Bool { diff --git a/Aztec/Classes/NSAttributedString/Attributes/HTMLRepresentation.swift b/Aztec/Classes/NSAttributedString/Attributes/HTMLRepresentation.swift index f14e60331..6c859b88e 100644 --- a/Aztec/Classes/NSAttributedString/Attributes/HTMLRepresentation.swift +++ b/Aztec/Classes/NSAttributedString/Attributes/HTMLRepresentation.swift @@ -2,7 +2,7 @@ import Foundation /// This enum specifies the different entities that can represent a style in HTML. /// -public class HTMLRepresentation: NSObject, NSCoding { +public class HTMLRepresentation: NSObject, NSSecureCoding { public enum Kind { case attribute(Attribute) case element(HTMLElementRepresentation) @@ -24,18 +24,18 @@ public class HTMLRepresentation: NSObject, NSCoding { } public required init?(coder aDecoder: NSCoder) { - if let attribute = aDecoder.decodeObject(forKey: Keys.attribute) as? Attribute { + if let attribute = aDecoder.decodeObject(of: Attribute.self, forKey: Keys.attribute) { kind = .attribute(attribute) return } - if let element = aDecoder.decodeObject(forKey: Keys.element) as? HTMLElementRepresentation { + if let element = aDecoder.decodeObject(of: HTMLElementRepresentation.self, forKey: Keys.element) { kind = .element(element) return } - if let rawCSS = aDecoder.decodeObject(forKey: Keys.inline) as? String, - let decodedCSS = CSSAttribute(for: rawCSS) { + if let rawCSS = aDecoder.decodeObject(of: NSString.self, forKey: Keys.inline), + let decodedCSS = CSSAttribute(for: rawCSS as String) { kind = .inlineCss(decodedCSS) return } @@ -53,12 +53,14 @@ public class HTMLRepresentation: NSObject, NSCoding { aCoder.encode(css.toString(), forKey: Keys.inline) } } + + public class var supportsSecureCoding: Bool { true } } // MARK: - HTMLElementRepresentation // -public class HTMLElementRepresentation: NSObject, CustomReflectable, NSCoding { +public class HTMLElementRepresentation: NSObject, CustomReflectable, NSSecureCoding { @objc let name: String @objc let attributes: [Attribute] @@ -78,13 +80,21 @@ public class HTMLElementRepresentation: NSObject, CustomReflectable, NSCoding { // MARK: - NSCoding public required convenience init?(coder aDecoder: NSCoder) { - guard let name = aDecoder.decodeObject(forKey: #keyPath(name)) as? String, - let attributes = aDecoder.decodeObject(forKey: #keyPath(attributes)) as? [Attribute] - else { + guard let name = aDecoder.decodeObject(of: NSString.self, forKey: #keyPath(name)) else { + fatalError() + } + let decodedAttributes: [Attribute]? + + if #available(iOS 14.0, *) { + decodedAttributes = aDecoder.decodeArrayOfObjects(ofClass: Attribute.self, forKey: #keyPath(attributes)) + } else { + decodedAttributes = aDecoder.decodeObject(of: NSArray.self, forKey: #keyPath(attributes)) as? [Attribute] + } + guard let attributes = decodedAttributes else { fatalError() } - self.init(name: name, attributes: attributes) + self.init(name: name as String, attributes: attributes) } open func encode(with aCoder: NSCoder) { @@ -92,6 +102,8 @@ public class HTMLElementRepresentation: NSObject, CustomReflectable, NSCoding { aCoder.encode(attributes, forKey: #keyPath(attributes)) } + public class var supportsSecureCoding: Bool { true } + // MARK: - CustomReflectable public var customMirror: Mirror { diff --git a/Aztec/Classes/NSAttributedString/Attributes/UnsupportedHTML.swift b/Aztec/Classes/NSAttributedString/Attributes/UnsupportedHTML.swift index 946b0a2e2..ace5b5556 100644 --- a/Aztec/Classes/NSAttributedString/Attributes/UnsupportedHTML.swift +++ b/Aztec/Classes/NSAttributedString/Attributes/UnsupportedHTML.swift @@ -3,7 +3,7 @@ import Foundation // MARK: - UnsupportedHTML // -class UnsupportedHTML: NSObject { +class UnsupportedHTML: NSObject, NSSecureCoding { /// ElementRepresentation for Unsupported HTML /// @@ -18,12 +18,20 @@ class UnsupportedHTML: NSObject { /// Required Initializers /// public required init?(coder aDecoder: NSCoder) { - guard let representations = aDecoder.decodeObject(forKey: Keys.representations) as? [HTMLElementRepresentation] else { - return nil + let representations: [HTMLElementRepresentation]? + if #available(iOS 14.0, *) { + representations = aDecoder.decodeArrayOfObjects(ofClass: HTMLElementRepresentation.self, forKey: Keys.representations) + } else { + representations = aDecoder.decodeObject(of: NSArray.self, forKey: Keys.representations) as? [HTMLElementRepresentation] } + guard let representations else { + return nil + } self.representations = representations } + + class var supportsSecureCoding: Bool { true } } diff --git a/Aztec/Classes/TextKit/CommentAttachment.swift b/Aztec/Classes/TextKit/CommentAttachment.swift index dd726b1b5..a2aeb3093 100644 --- a/Aztec/Classes/TextKit/CommentAttachment.swift +++ b/Aztec/Classes/TextKit/CommentAttachment.swift @@ -32,11 +32,11 @@ open class CommentAttachment: NSTextAttachment, RenderableAttachment { public required init?(coder aDecoder: NSCoder) { super.init(data: nil, ofType: nil) - guard let text = aDecoder.decodeObject(forKey: Keys.text) as? String else { + guard let text = aDecoder.decodeObject(of: NSString.self, forKey: Keys.text) else { return } - self.text = text + self.text = text as String } @@ -48,7 +48,7 @@ open class CommentAttachment: NSTextAttachment, RenderableAttachment { aCoder.encode(text, forKey: Keys.text) } - + override public class var supportsSecureCoding: Bool { true } // MARK: - NSTextAttachmentContainer diff --git a/Aztec/Classes/TextKit/HTMLAttachment.swift b/Aztec/Classes/TextKit/HTMLAttachment.swift index 971f0bb8a..464601f25 100644 --- a/Aztec/Classes/TextKit/HTMLAttachment.swift +++ b/Aztec/Classes/TextKit/HTMLAttachment.swift @@ -40,16 +40,17 @@ open class HTMLAttachment: NSTextAttachment, RenderableAttachment { public required init?(coder aDecoder: NSCoder) { super.init(data: nil, ofType: nil) - guard let rootTagName = aDecoder.decodeObject(forKey: Keys.rootTagName) as? String, - let rawHTML = aDecoder.decodeObject(forKey: Keys.rawHTML) as? String + guard let rootTagName = aDecoder.decodeObject(of: NSString.self, forKey: Keys.rootTagName), + let rawHTML = aDecoder.decodeObject(of: NSString.self, forKey: Keys.rawHTML) else { return } - self.rootTagName = rootTagName - self.rawHTML = rawHTML + self.rootTagName = rootTagName as String + self.rawHTML = rawHTML as String } + override public class var supportsSecureCoding: Bool { true } /// Extracts the root tag name from a given HTML string /// diff --git a/Aztec/Classes/TextKit/ImageAttachment.swift b/Aztec/Classes/TextKit/ImageAttachment.swift index 60007086f..f60f170f0 100644 --- a/Aztec/Classes/TextKit/ImageAttachment.swift +++ b/Aztec/Classes/TextKit/ImageAttachment.swift @@ -74,6 +74,8 @@ open class ImageAttachment: MediaAttachment { aCoder.encode(size.rawValue, forKey: EncodeKeys.size.rawValue) } + override public class var supportsSecureCoding: Bool { true } + private enum EncodeKeys: String { case alignment case size diff --git a/Aztec/Classes/TextKit/MediaAttachment.swift b/Aztec/Classes/TextKit/MediaAttachment.swift index b2265d5df..53faa52ab 100644 --- a/Aztec/Classes/TextKit/MediaAttachment.swift +++ b/Aztec/Classes/TextKit/MediaAttachment.swift @@ -153,10 +153,12 @@ open class MediaAttachment: NSTextAttachment { /// super.init(coder: aDecoder) - identifier = aDecoder.decodeObject(forKey: EncodeKeys.identifier.rawValue) as? String ?? identifier - url = aDecoder.decodeObject(forKey: EncodeKeys.url.rawValue) as? URL + identifier = aDecoder.decodeObject(of: NSString.self, forKey: EncodeKeys.identifier.rawValue) as? String ?? identifier + url = aDecoder.decodeObject(of: NSURL.self, forKey: EncodeKeys.url.rawValue) as? URL } + override public class var supportsSecureCoding: Bool { true } + /// Required Initializer /// override required public init(data contentData: Data?, ofType uti: String?) { diff --git a/Aztec/Classes/TextKit/ParagraphProperty/Blockquote.swift b/Aztec/Classes/TextKit/ParagraphProperty/Blockquote.swift index 4e8de163f..477b533a2 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/Blockquote.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/Blockquote.swift @@ -6,6 +6,8 @@ class Blockquote: ParagraphProperty { super.encode(with: aCoder) } + override public class var supportsSecureCoding: Bool { true } + override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) } diff --git a/Aztec/Classes/TextKit/ParagraphProperty/Figcaption.swift b/Aztec/Classes/TextKit/ParagraphProperty/Figcaption.swift index 388d6fb11..9c23bed4e 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/Figcaption.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/Figcaption.swift @@ -10,7 +10,7 @@ class Figcaption: ParagraphProperty { } required public init?(coder aDecoder: NSCoder){ - defaultFont = aDecoder.decodeObject(forKey: CodingKeys.defaultFont) as! UIFont + defaultFont = aDecoder.decodeObject(of: UIFont.self, forKey: CodingKeys.defaultFont)! super.init(coder: aDecoder) } @@ -18,6 +18,8 @@ class Figcaption: ParagraphProperty { super.encode(with: aCoder) aCoder.encode(defaultFont, forKey: CodingKeys.defaultFont) } + + override public class var supportsSecureCoding: Bool { true } } private extension Figcaption { diff --git a/Aztec/Classes/TextKit/ParagraphProperty/Figure.swift b/Aztec/Classes/TextKit/ParagraphProperty/Figure.swift index ef2c75dc9..beffb410e 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/Figure.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/Figure.swift @@ -5,7 +5,9 @@ class Figure: ParagraphProperty { public override func encode(with aCoder: NSCoder) { super.encode(with: aCoder) } - + + override public class var supportsSecureCoding: Bool { true } + override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) } diff --git a/Aztec/Classes/TextKit/ParagraphProperty/HTMLDiv.swift b/Aztec/Classes/TextKit/ParagraphProperty/HTMLDiv.swift index 7dd45a23a..15947898d 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/HTMLDiv.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/HTMLDiv.swift @@ -9,6 +9,8 @@ class HTMLDiv: ParagraphProperty { super.encode(with: aCoder) } + override public class var supportsSecureCoding: Bool { true } + override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) } diff --git a/Aztec/Classes/TextKit/ParagraphProperty/HTMLLi.swift b/Aztec/Classes/TextKit/ParagraphProperty/HTMLLi.swift index 2b0310058..0485360b3 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/HTMLLi.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/HTMLLi.swift @@ -6,6 +6,8 @@ class HTMLLi: ParagraphProperty { super.encode(with: aCoder) } + override public class var supportsSecureCoding: Bool { true } + override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) } diff --git a/Aztec/Classes/TextKit/ParagraphProperty/HTMLParagraph.swift b/Aztec/Classes/TextKit/ParagraphProperty/HTMLParagraph.swift index 83aa956a9..9432886f7 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/HTMLParagraph.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/HTMLParagraph.swift @@ -9,6 +9,8 @@ class HTMLParagraph: ParagraphProperty { super.encode(with: aCoder) } + override public class var supportsSecureCoding: Bool { true } + override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) } diff --git a/Aztec/Classes/TextKit/ParagraphProperty/HTMLPre.swift b/Aztec/Classes/TextKit/ParagraphProperty/HTMLPre.swift index d8049c139..ca043a51c 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/HTMLPre.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/HTMLPre.swift @@ -6,6 +6,8 @@ class HTMLPre: ParagraphProperty { super.encode(with: aCoder) } + override public class var supportsSecureCoding: Bool { true } + override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) } diff --git a/Aztec/Classes/TextKit/ParagraphProperty/Header.swift b/Aztec/Classes/TextKit/ParagraphProperty/Header.swift index a13dafe0c..d5120720a 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/Header.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/Header.swift @@ -83,6 +83,8 @@ open class Header: ParagraphProperty { aCoder.encode(level.rawValue, forKey: Keys.level) } + override public class var supportsSecureCoding: Bool { true } + static func ==(lhs: Header, rhs: Header) -> Bool { return lhs.level == rhs.level } diff --git a/Aztec/Classes/TextKit/ParagraphProperty/ParagraphProperty.swift b/Aztec/Classes/TextKit/ParagraphProperty/ParagraphProperty.swift index 0a6e54180..79ad14b59 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/ParagraphProperty.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/ParagraphProperty.swift @@ -1,6 +1,6 @@ import Foundation -open class ParagraphProperty: NSObject, NSCoding { +open class ParagraphProperty: NSObject, NSSecureCoding { open var representation: HTMLRepresentation? @@ -19,6 +19,8 @@ open class ParagraphProperty: NSObject, NSCoding { public func encode(with aCoder: NSCoder) { } + public class var supportsSecureCoding: Bool { true } + static func ==(lhs: ParagraphProperty, rhs: ParagraphProperty) -> Bool { return lhs === rhs } diff --git a/Aztec/Classes/TextKit/ParagraphProperty/TextList.swift b/Aztec/Classes/TextKit/ParagraphProperty/TextList.swift index a2cf28306..904118e4e 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/TextList.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/TextList.swift @@ -84,6 +84,8 @@ open class TextList: ParagraphProperty { aCoder.encode(reversed, forKey: AttributeType.reversed.rawValue) } + override public class var supportsSecureCoding: Bool { true } + public static func ==(lhs: TextList, rhs: TextList) -> Bool { return lhs.style == rhs.style && lhs.start == rhs.start && lhs.reversed == rhs.reversed } diff --git a/Aztec/Classes/TextKit/ParagraphStyle.swift b/Aztec/Classes/TextKit/ParagraphStyle.swift index eb01f7029..87d72ece9 100644 --- a/Aztec/Classes/TextKit/ParagraphStyle.swift +++ b/Aztec/Classes/TextKit/ParagraphStyle.swift @@ -89,7 +89,14 @@ open class ParagraphStyle: NSMutableParagraphStyle, CustomReflectable { public required init?(coder aDecoder: NSCoder) { - if let encodedProperties = aDecoder.decodeObject(forKey:String(describing: ParagraphProperty.self)) as? [ParagraphProperty] { + let encodedProperties: [ParagraphProperty]? + if #available(iOS 14.0, *) { + encodedProperties = aDecoder.decodeArrayOfObjects(ofClass: ParagraphProperty.self, forKey: String(describing: ParagraphProperty.self)) + } else { + encodedProperties = aDecoder.decodeObject(of: NSArray.self, forKey: String(describing: ParagraphProperty.self)) as? [ParagraphProperty] + } + + if let encodedProperties { properties = encodedProperties } @@ -105,6 +112,8 @@ open class ParagraphStyle: NSMutableParagraphStyle, CustomReflectable { aCoder.encode(headerLevel, forKey: EncodingKeys.headerLevel.rawValue) } + override public class var supportsSecureCoding: Bool { true } + override open func setParagraphStyle(_ baseParagraphStyle: NSParagraphStyle) { super.setParagraphStyle(baseParagraphStyle) diff --git a/Aztec/Classes/TextKit/VideoAttachment.swift b/Aztec/Classes/TextKit/VideoAttachment.swift index 35df36209..89e82c994 100644 --- a/Aztec/Classes/TextKit/VideoAttachment.swift +++ b/Aztec/Classes/TextKit/VideoAttachment.swift @@ -39,10 +39,12 @@ open class VideoAttachment: MediaAttachment { super.init(coder: aDecoder) if aDecoder.containsValue(forKey: EncodeKeys.posterURL.rawValue) { - posterURL = aDecoder.decodeObject(forKey: EncodeKeys.posterURL.rawValue) as? URL + posterURL = aDecoder.decodeObject(of: NSURL.self, forKey: EncodeKeys.posterURL.rawValue) as? URL } } + override public class var supportsSecureCoding: Bool { true } + /// Required Initializer /// required public init(identifier: String, url: URL?) { diff --git a/AztecTests/TextKit/HTMLRepresentationTests.swift b/AztecTests/TextKit/HTMLRepresentationTests.swift index 47c46b762..6a6998efc 100644 --- a/AztecTests/TextKit/HTMLRepresentationTests.swift +++ b/AztecTests/TextKit/HTMLRepresentationTests.swift @@ -8,9 +8,9 @@ class HTMLRepresentationTests: XCTestCase { /// Verifies that HTMLRepresentation of Attribute kind is properly serialized Back and Forth /// - func testAttibuteRepresentationGetsProperlySerializedAndRestored() { + func testAttibuteRepresentationGetsProperlySerializedAndRestored() throws { let representation = HTMLRepresentation(for: .attribute(sampleAttribute)) - let regenerated = regenerate(representation: representation) + let regenerated = try regenerate(representation: representation) guard case let .attribute(attribute) = regenerated.kind else { XCTFail() @@ -22,9 +22,9 @@ class HTMLRepresentationTests: XCTestCase { /// Verifies that HTMLRepresentation of Element kind is properly serialized Back and Forth /// - func testElementRepresentationGetsProperlySerializedAndRestored() { + func testElementRepresentationGetsProperlySerializedAndRestored() throws { let representation = HTMLRepresentation(for: .element(sampleElement)) - let regenerated = regenerate(representation: representation) + let regenerated = try regenerate(representation: representation) guard case let .element(element) = regenerated.kind else { XCTFail() @@ -36,9 +36,9 @@ class HTMLRepresentationTests: XCTestCase { /// Verifies that HTMLRepresentation of inlineCSS kind is properly serialized Back and Forth /// - func testCssRepresentationGetsProperlySerializedAndRestored() { + func testCssRepresentationGetsProperlySerializedAndRestored() throws { let representation = HTMLRepresentation(for: .inlineCss(sampleCSS)) - let regenerated = regenerate(representation: representation) + let regenerated = try regenerate(representation: representation) guard case let .inlineCss(css) = regenerated.kind else { XCTFail() @@ -67,12 +67,10 @@ private extension HTMLRepresentationTests { return HTMLElementRepresentation(name: "table", attributes: [sampleAttribute]) } - func regenerate(representation: HTMLRepresentation) -> HTMLRepresentation { - let data = NSKeyedArchiver.archivedData(withRootObject: representation) - guard let restored = NSKeyedUnarchiver.unarchiveObject(with: data) as? HTMLRepresentation else { - fatalError() - } + func regenerate(representation: HTMLRepresentation) throws -> HTMLRepresentation { + let data = try NSKeyedArchiver.archivedData(withRootObject: representation, requiringSecureCoding: false) + let restored = try NSKeyedUnarchiver.unarchivedObject(ofClass: HTMLRepresentation.self, from: data) - return restored + return restored! } } diff --git a/AztecTests/TextKit/UnsupportedHTMLTests.swift b/AztecTests/TextKit/UnsupportedHTMLTests.swift index 11b100ad6..2588953a5 100644 --- a/AztecTests/TextKit/UnsupportedHTMLTests.swift +++ b/AztecTests/TextKit/UnsupportedHTMLTests.swift @@ -8,11 +8,11 @@ class UnsupportedHTMLTests: XCTestCase { /// Verifies that a UnsupportedHTML Instance can get properly serialized back and forth /// - func testSnippetsGetProperlyEncodedAndDecoded() { + func testSnippetsGetProperlyEncodedAndDecoded() throws { let unsupported = UnsupportedHTML(representations: [sampleRepresentation, sampleRepresentation]) - let data = NSKeyedArchiver.archivedData(withRootObject: unsupported) - guard let restored = NSKeyedUnarchiver.unarchiveObject(with: data) as? UnsupportedHTML else { + let data = try NSKeyedArchiver.archivedData(withRootObject: unsupported, requiringSecureCoding: false) + guard let restored = try NSKeyedUnarchiver.unarchivedObject(ofClass: UnsupportedHTML.self, from: data) else { XCTFail() return } diff --git a/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift b/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift index 6ead4ee47..655d2887c 100644 --- a/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift +++ b/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift @@ -10,4 +10,7 @@ class Gutenblock: ParagraphProperty { required public init?(coder aDecoder: NSCoder){ super.init(coder: aDecoder) } + + override public class var supportsSecureCoding: Bool { true } + } diff --git a/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/GutenpackAttachment.swift b/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/GutenpackAttachment.swift index 784343f0d..f45d42e4f 100644 --- a/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/GutenpackAttachment.swift +++ b/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/GutenpackAttachment.swift @@ -17,14 +17,14 @@ class GutenpackAttachment: NSTextAttachment, RenderableAttachment { let blockContent: String required init?(coder aDecoder: NSCoder) { - guard let blockName = aDecoder.decodeObject(forKey: EncodingKeys.blockName) as? String, - let blockContent = aDecoder.decodeObject(forKey: EncodingKeys.blockContent) as? String + guard let blockName = aDecoder.decodeObject(of: NSString.self, forKey: EncodingKeys.blockName), + let blockContent = aDecoder.decodeObject(of: NSString.self, forKey: EncodingKeys.blockContent) else { return nil } - self.blockName = blockName - self.blockContent = blockContent + self.blockName = blockName as String + self.blockContent = blockContent as String super.init(coder: aDecoder) } From 90c0e4db1246dc4e87f004c4ec96061399447efb Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Thu, 18 Apr 2024 14:26:18 +0200 Subject: [PATCH 12/17] Use `UTType.utf8PlainText` (explicit encoding) instead of `kUTTypePlainText` Since newer versions of iOS use this new `public.utf8-plain-text` UTI instead of `public.plain-text` like in previous OS versions. --- .../NSAttributedString+Archive.swift | 3 +- .../Extensions/UIPasteboard+Helpers.swift | 87 +++++++++++++++++-- Aztec/Classes/TextKit/TextView.swift | 18 +--- .../Extensions/UIPasteboardHelpersTests.swift | 4 +- AztecTests/TextKit/TextViewTests.swift | 6 +- 5 files changed, 88 insertions(+), 30 deletions(-) diff --git a/Aztec/Classes/Extensions/NSAttributedString+Archive.swift b/Aztec/Classes/Extensions/NSAttributedString+Archive.swift index 81997e2e1..fd1c484b3 100644 --- a/Aztec/Classes/Extensions/NSAttributedString+Archive.swift +++ b/Aztec/Classes/Extensions/NSAttributedString+Archive.swift @@ -1,10 +1,11 @@ import Foundation +import UIKit // MARK: - NSAttributedString Archive methods // extension NSAttributedString { - static let pastesboardUTI = "com.wordpress.aztec.attributedString" + static let pasteboardUTI = UIPasteboard.UTType(identifier: "com.wordpress.aztec.attributedString") func archivedData() throws -> Data { return try NSKeyedArchiver.archivedData(withRootObject: self, requiringSecureCoding: false) diff --git a/Aztec/Classes/Extensions/UIPasteboard+Helpers.swift b/Aztec/Classes/Extensions/UIPasteboard+Helpers.swift index 46be4e0ad..47c9816b3 100644 --- a/Aztec/Classes/Extensions/UIPasteboard+Helpers.swift +++ b/Aztec/Classes/Extensions/UIPasteboard+Helpers.swift @@ -1,4 +1,5 @@ import Foundation +import UniformTypeIdentifiers import MobileCoreServices import UIKit @@ -30,12 +31,81 @@ extension UIPasteboard { } func html() -> String? { - guard let htmlData = data(forPasteboardType: String(kUTTypeHTML)) else { + guard let htmlData = data(forPasteboardType: UTType.html.identifier) else { return nil } return String(data: htmlData, encoding: .utf8) } + + // Compatibility Helper for using UTType before iOS14's UniformTypeIdentifiers + // Feel free to remove once Deployment Target of the project gets bumped to >14.0 + struct UTType { + let identifier: String + + static let html: UTType = { + UTType(identifier: { + if #available(iOS 14.0, *) { + UniformTypeIdentifiers.UTType.html.identifier + } else { + kUTTypeHTML as String + } + }()) + }() + static let plainText: UTType = { + UTType(identifier: { + if #available(iOS 14.0, *) { + UniformTypeIdentifiers.UTType.utf8PlainText.identifier + } else { + kUTTypeUTF8PlainText as String + } + }()) + }() + static let richText: UTType = { + UTType(identifier: { + if #available(iOS 14.0, *) { + UniformTypeIdentifiers.UTType.text.identifier + } else { + kUTTypeText as String + } + }()) + }() + static let RTFText: UTType = { + UTType(identifier: { + if #available(iOS 14.0, *) { + UniformTypeIdentifiers.UTType.rtf.identifier + } else { + kUTTypeRTF as String + } + }()) + }() + static let RTFDText: UTType = { + UTType(identifier: { + if #available(iOS 14.0, *) { + UniformTypeIdentifiers.UTType.flatRTFD.identifier + } else { + kUTTypeFlatRTFD as String + } + }()) + }() + static let URL: UTType = { + UTType(identifier: { + if #available(iOS 14.0, *) { + UniformTypeIdentifiers.UTType.url.identifier + } else { + kUTTypeURL as String + } + }()) + }() + } + + func store(_ data: Any, as type: UTType) { + if numberOfItems > 0 { + items[0][type.identifier] = data + } else { + addItems([[type.identifier: data]]) + } + } } // MARK: - Attributed String Conversion @@ -43,11 +113,10 @@ extension UIPasteboard { private extension UIPasteboard { // MARK: - - /// Attempts to unarchive the Pasteboard's Aztec-Archived String /// private func aztecAttributedString() -> NSAttributedString? { - guard let data = data(forPasteboardType: NSAttributedString.pastesboardUTI) else { + guard let data = data(forPasteboardType: NSAttributedString.pasteboardUTI.identifier) else { return nil } @@ -57,25 +126,25 @@ private extension UIPasteboard { /// Attempts to unarchive the Pasteboard's Plain Text contents into an Attributed String /// private func plainTextAttributedString() -> NSAttributedString? { - return unarchiveAttributedString(fromPasteboardCFType: kUTTypePlainText, with: StringOptions.plainText) + return unarchiveAttributedString(fromPasteboardType: .plainText, with: StringOptions.plainText) } /// Attempts to unarchive the Pasteboard's Text contents into an Attributed String /// private func richTextAttributedString() -> NSAttributedString? { - return unarchiveAttributedString(fromPasteboardCFType: kUTTypeText, with: StringOptions.RTFText) + return unarchiveAttributedString(fromPasteboardType: .richText, with: StringOptions.RTFText) } /// Attempts to unarchive the Pasteboard's RTF contents into an Attributed String /// private func rtfAttributedString() -> NSAttributedString? { - return unarchiveAttributedString(fromPasteboardCFType: kUTTypeRTF, with: StringOptions.RTFText) + return unarchiveAttributedString(fromPasteboardType: .RTFText, with: StringOptions.RTFText) } /// Attempts to unarchive the Pasteboard's RTFD contents into an Attributed String /// private func rtfdAttributedString() -> NSAttributedString? { - return unarchiveAttributedString(fromPasteboardCFType: kUTTypeFlatRTFD, with: StringOptions.RTFDText) + return unarchiveAttributedString(fromPasteboardType: .RTFDText, with: StringOptions.RTFDText) } // MARK: - Helpers @@ -97,8 +166,8 @@ private extension UIPasteboard { /// /// - Returns: NSAttributed String with the contents of the specified Pasteboard entry, if any. /// - private func unarchiveAttributedString(fromPasteboardCFType type: CFString, with options: [DocumentReadingOptionKey: Any]) -> NSAttributedString? { - guard let data = data(forPasteboardType: String(type)) else { + private func unarchiveAttributedString(fromPasteboardType type: UTType, with options: [DocumentReadingOptionKey: Any]) -> NSAttributedString? { + guard let data = data(forPasteboardType: type.identifier) else { return nil } diff --git a/Aztec/Classes/TextKit/TextView.swift b/Aztec/Classes/TextKit/TextView.swift index af96101d4..26ecc5acb 100644 --- a/Aztec/Classes/TextKit/TextView.swift +++ b/Aztec/Classes/TextKit/TextView.swift @@ -668,27 +668,15 @@ open class TextView: UITextView { // MARK: - Pasteboard Helpers internal func storeInPasteboard(encoded data: Data) { - if pasteboard.numberOfItems > 0 { - pasteboard.items[0][NSAttributedString.pastesboardUTI] = data - } else { - pasteboard.addItems([[NSAttributedString.pastesboardUTI: data]]) - } + pasteboard.store(data, as: NSAttributedString.pasteboardUTI) } internal func storeInPasteboard(html: String) { - if pasteboard.numberOfItems > 0 { - pasteboard.items[0][kUTTypeHTML as String] = html - } else { - pasteboard.addItems([[kUTTypeHTML as String: html]]) - } + pasteboard.store(html, as: .html) } internal func storeInPasteboard(plain: String) { - if pasteboard.numberOfItems > 0 { - pasteboard.items[0][kUTTypePlainText as String] = plain - } else { - pasteboard.addItems([[kUTTypePlainText as String: plain]]) - } + pasteboard.store(plain, as: .plainText) } // MARK: - Intercept keyboard operations diff --git a/AztecTests/Extensions/UIPasteboardHelpersTests.swift b/AztecTests/Extensions/UIPasteboardHelpersTests.swift index b0dca6faf..c9ed1a626 100644 --- a/AztecTests/Extensions/UIPasteboardHelpersTests.swift +++ b/AztecTests/Extensions/UIPasteboardHelpersTests.swift @@ -30,7 +30,7 @@ class UIPasteboardHelpersTests: XCTestCase { return } - pasteboard.setData(data, forPasteboardType: String(kUTTypeFlatRTFD)) + pasteboard.setData(data, forPasteboardType: UIPasteboard.UTType.RTFDText.identifier) guard let pastedString = pasteboard.attributedString() else { XCTFail() @@ -46,7 +46,7 @@ class UIPasteboardHelpersTests: XCTestCase { let pasteboard = UIPasteboard.forTesting let html = "

testing

" - pasteboard.setValue(html, forPasteboardType: String(kUTTypeHTML)) + pasteboard.setValue(html, forPasteboardType: UIPasteboard.UTType.html.identifier) XCTAssertEqual(pasteboard.html(), html) } diff --git a/AztecTests/TextKit/TextViewTests.swift b/AztecTests/TextKit/TextViewTests.swift index a8c3325f3..e8449b282 100644 --- a/AztecTests/TextKit/TextViewTests.swift +++ b/AztecTests/TextKit/TextViewTests.swift @@ -1985,7 +1985,7 @@ class TextViewTests: XCTestCase { let textView = TextViewStub(withHTML: "") let url = URL(string: "http://wordpress.com")! - UIPasteboard.forTesting.setValue(url, forPasteboardType: String(kUTTypeURL)) + UIPasteboard.forTesting.setValue(url, forPasteboardType: UIPasteboard.UTType.URL.identifier) textView.paste(nil) @@ -1997,7 +1997,7 @@ class TextViewTests: XCTestCase { let textView = TextViewStub(withHTML: "WordPress") let url = URL(string: "http://wordpress.com")! - UIPasteboard.forTesting.setValue(url, forPasteboardType: String(kUTTypeURL)) + UIPasteboard.forTesting.setValue(url, forPasteboardType: UIPasteboard.UTType.URL.identifier) textView.selectedRange = NSRange(location: 0, length: 9) textView.paste(nil) @@ -2082,7 +2082,7 @@ class TextViewTests: XCTestCase { func testPasteAttributedText() { let sourceAttributedText = NSAttributedString(string: "Hello world") var pasteItems = [String:Any]() - pasteItems[kUTTypePlainText as String] = try! sourceAttributedText.data(from: sourceAttributedText.rangeOfEntireString, documentAttributes: [.documentType: DocumentType.plain]) + pasteItems[UIPasteboard.UTType.plainText.identifier] = try! sourceAttributedText.data(from: sourceAttributedText.rangeOfEntireString, documentAttributes: [.documentType: DocumentType.plain]) UIPasteboard.forTesting.setItems([pasteItems], options: [:]) let textView = TextViewStub(withHTML: "") textView.textColor = UIColor.red From 5c3004b944eed56f286c7034ac02ea9d2716137c Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Thu, 18 Apr 2024 14:31:08 +0200 Subject: [PATCH 13/17] Fix overriding non-open class outside module --- .../Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift b/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift index 655d2887c..6ead4ee47 100644 --- a/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift +++ b/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift @@ -10,7 +10,4 @@ class Gutenblock: ParagraphProperty { required public init?(coder aDecoder: NSCoder){ super.init(coder: aDecoder) } - - override public class var supportsSecureCoding: Bool { true } - } From e21dbff95064b99a602894ec5667d92fa80b8f68 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Thu, 18 Apr 2024 14:33:46 +0200 Subject: [PATCH 14/17] Revert "Fix overriding non-open class outside module" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 5c3004b944eed56f286c7034ac02ea9d2716137c, because I'm not convinced that's a good idea. We should double-check that **not** having `+supportsSecureCoding` declared on this subclass doesn't make it fail to be copy/pasted (i.e. archived/unarchived)—like similar cases happened when running Aztec tests. Or if we need `+supportsSecureCoding`, we need to find a way to override/redefine it across module boundaries… --- .../Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift b/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift index 6ead4ee47..655d2887c 100644 --- a/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift +++ b/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift @@ -10,4 +10,7 @@ class Gutenblock: ParagraphProperty { required public init?(coder aDecoder: NSCoder){ super.init(coder: aDecoder) } + + override public class var supportsSecureCoding: Bool { true } + } From c67821c78617edabda0ddea1d97b1597470e656f Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Thu, 18 Apr 2024 14:41:54 +0200 Subject: [PATCH 15/17] Declare `class var supportsSecureCoding` as `open` --- Aztec/Classes/Libxml2/DOM/Data/Attribute.swift | 2 +- .../NSAttributedString/Attributes/HTMLRepresentation.swift | 4 ++-- .../NSAttributedString/Attributes/UnsupportedHTML.swift | 2 +- Aztec/Classes/TextKit/CommentAttachment.swift | 2 +- Aztec/Classes/TextKit/HTMLAttachment.swift | 2 +- Aztec/Classes/TextKit/ImageAttachment.swift | 2 +- Aztec/Classes/TextKit/MediaAttachment.swift | 2 +- Aztec/Classes/TextKit/ParagraphProperty/Blockquote.swift | 2 +- Aztec/Classes/TextKit/ParagraphProperty/Figcaption.swift | 2 +- Aztec/Classes/TextKit/ParagraphProperty/Figure.swift | 2 +- Aztec/Classes/TextKit/ParagraphProperty/HTMLDiv.swift | 2 +- Aztec/Classes/TextKit/ParagraphProperty/HTMLLi.swift | 2 +- Aztec/Classes/TextKit/ParagraphProperty/HTMLParagraph.swift | 2 +- Aztec/Classes/TextKit/ParagraphProperty/HTMLPre.swift | 2 +- Aztec/Classes/TextKit/ParagraphProperty/Header.swift | 2 +- .../Classes/TextKit/ParagraphProperty/ParagraphProperty.swift | 2 +- Aztec/Classes/TextKit/ParagraphProperty/TextList.swift | 2 +- Aztec/Classes/TextKit/ParagraphStyle.swift | 2 +- Aztec/Classes/TextKit/VideoAttachment.swift | 2 +- .../Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift | 2 +- 20 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Aztec/Classes/Libxml2/DOM/Data/Attribute.swift b/Aztec/Classes/Libxml2/DOM/Data/Attribute.swift index ef50ef97f..bbcf7fafd 100644 --- a/Aztec/Classes/Libxml2/DOM/Data/Attribute.swift +++ b/Aztec/Classes/Libxml2/DOM/Data/Attribute.swift @@ -72,7 +72,7 @@ public class Attribute: NSObject, CustomReflectable, NSSecureCoding { } } - public class var supportsSecureCoding: Bool { true } + open class var supportsSecureCoding: Bool { true } // MARK: - Equatable diff --git a/Aztec/Classes/NSAttributedString/Attributes/HTMLRepresentation.swift b/Aztec/Classes/NSAttributedString/Attributes/HTMLRepresentation.swift index 6c859b88e..1552e567c 100644 --- a/Aztec/Classes/NSAttributedString/Attributes/HTMLRepresentation.swift +++ b/Aztec/Classes/NSAttributedString/Attributes/HTMLRepresentation.swift @@ -54,7 +54,7 @@ public class HTMLRepresentation: NSObject, NSSecureCoding { } } - public class var supportsSecureCoding: Bool { true } + open class var supportsSecureCoding: Bool { true } } @@ -102,7 +102,7 @@ public class HTMLElementRepresentation: NSObject, CustomReflectable, NSSecureCod aCoder.encode(attributes, forKey: #keyPath(attributes)) } - public class var supportsSecureCoding: Bool { true } + open class var supportsSecureCoding: Bool { true } // MARK: - CustomReflectable diff --git a/Aztec/Classes/NSAttributedString/Attributes/UnsupportedHTML.swift b/Aztec/Classes/NSAttributedString/Attributes/UnsupportedHTML.swift index ace5b5556..cd5abed3d 100644 --- a/Aztec/Classes/NSAttributedString/Attributes/UnsupportedHTML.swift +++ b/Aztec/Classes/NSAttributedString/Attributes/UnsupportedHTML.swift @@ -31,7 +31,7 @@ class UnsupportedHTML: NSObject, NSSecureCoding { self.representations = representations } - class var supportsSecureCoding: Bool { true } + open class var supportsSecureCoding: Bool { true } } diff --git a/Aztec/Classes/TextKit/CommentAttachment.swift b/Aztec/Classes/TextKit/CommentAttachment.swift index a2aeb3093..b53c4d758 100644 --- a/Aztec/Classes/TextKit/CommentAttachment.swift +++ b/Aztec/Classes/TextKit/CommentAttachment.swift @@ -48,7 +48,7 @@ open class CommentAttachment: NSTextAttachment, RenderableAttachment { aCoder.encode(text, forKey: Keys.text) } - override public class var supportsSecureCoding: Bool { true } + override open class var supportsSecureCoding: Bool { true } // MARK: - NSTextAttachmentContainer diff --git a/Aztec/Classes/TextKit/HTMLAttachment.swift b/Aztec/Classes/TextKit/HTMLAttachment.swift index 464601f25..95ad8e98b 100644 --- a/Aztec/Classes/TextKit/HTMLAttachment.swift +++ b/Aztec/Classes/TextKit/HTMLAttachment.swift @@ -50,7 +50,7 @@ open class HTMLAttachment: NSTextAttachment, RenderableAttachment { self.rawHTML = rawHTML as String } - override public class var supportsSecureCoding: Bool { true } + override open class var supportsSecureCoding: Bool { true } /// Extracts the root tag name from a given HTML string /// diff --git a/Aztec/Classes/TextKit/ImageAttachment.swift b/Aztec/Classes/TextKit/ImageAttachment.swift index f60f170f0..30d175aa4 100644 --- a/Aztec/Classes/TextKit/ImageAttachment.swift +++ b/Aztec/Classes/TextKit/ImageAttachment.swift @@ -74,7 +74,7 @@ open class ImageAttachment: MediaAttachment { aCoder.encode(size.rawValue, forKey: EncodeKeys.size.rawValue) } - override public class var supportsSecureCoding: Bool { true } + override open class var supportsSecureCoding: Bool { true } private enum EncodeKeys: String { case alignment diff --git a/Aztec/Classes/TextKit/MediaAttachment.swift b/Aztec/Classes/TextKit/MediaAttachment.swift index 53faa52ab..52213c12a 100644 --- a/Aztec/Classes/TextKit/MediaAttachment.swift +++ b/Aztec/Classes/TextKit/MediaAttachment.swift @@ -157,7 +157,7 @@ open class MediaAttachment: NSTextAttachment { url = aDecoder.decodeObject(of: NSURL.self, forKey: EncodeKeys.url.rawValue) as? URL } - override public class var supportsSecureCoding: Bool { true } + override open class var supportsSecureCoding: Bool { true } /// Required Initializer /// diff --git a/Aztec/Classes/TextKit/ParagraphProperty/Blockquote.swift b/Aztec/Classes/TextKit/ParagraphProperty/Blockquote.swift index 477b533a2..836736103 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/Blockquote.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/Blockquote.swift @@ -6,7 +6,7 @@ class Blockquote: ParagraphProperty { super.encode(with: aCoder) } - override public class var supportsSecureCoding: Bool { true } + override open class var supportsSecureCoding: Bool { true } override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) diff --git a/Aztec/Classes/TextKit/ParagraphProperty/Figcaption.swift b/Aztec/Classes/TextKit/ParagraphProperty/Figcaption.swift index 9c23bed4e..0b7410136 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/Figcaption.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/Figcaption.swift @@ -19,7 +19,7 @@ class Figcaption: ParagraphProperty { aCoder.encode(defaultFont, forKey: CodingKeys.defaultFont) } - override public class var supportsSecureCoding: Bool { true } + override open class var supportsSecureCoding: Bool { true } } private extension Figcaption { diff --git a/Aztec/Classes/TextKit/ParagraphProperty/Figure.swift b/Aztec/Classes/TextKit/ParagraphProperty/Figure.swift index beffb410e..c9ae130af 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/Figure.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/Figure.swift @@ -6,7 +6,7 @@ class Figure: ParagraphProperty { super.encode(with: aCoder) } - override public class var supportsSecureCoding: Bool { true } + override open class var supportsSecureCoding: Bool { true } override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) diff --git a/Aztec/Classes/TextKit/ParagraphProperty/HTMLDiv.swift b/Aztec/Classes/TextKit/ParagraphProperty/HTMLDiv.swift index 15947898d..7465e9e53 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/HTMLDiv.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/HTMLDiv.swift @@ -9,7 +9,7 @@ class HTMLDiv: ParagraphProperty { super.encode(with: aCoder) } - override public class var supportsSecureCoding: Bool { true } + override open class var supportsSecureCoding: Bool { true } override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) diff --git a/Aztec/Classes/TextKit/ParagraphProperty/HTMLLi.swift b/Aztec/Classes/TextKit/ParagraphProperty/HTMLLi.swift index 0485360b3..ad4cb8617 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/HTMLLi.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/HTMLLi.swift @@ -6,7 +6,7 @@ class HTMLLi: ParagraphProperty { super.encode(with: aCoder) } - override public class var supportsSecureCoding: Bool { true } + override open class var supportsSecureCoding: Bool { true } override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) diff --git a/Aztec/Classes/TextKit/ParagraphProperty/HTMLParagraph.swift b/Aztec/Classes/TextKit/ParagraphProperty/HTMLParagraph.swift index 9432886f7..ea04ec83a 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/HTMLParagraph.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/HTMLParagraph.swift @@ -9,7 +9,7 @@ class HTMLParagraph: ParagraphProperty { super.encode(with: aCoder) } - override public class var supportsSecureCoding: Bool { true } + override open class var supportsSecureCoding: Bool { true } override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) diff --git a/Aztec/Classes/TextKit/ParagraphProperty/HTMLPre.swift b/Aztec/Classes/TextKit/ParagraphProperty/HTMLPre.swift index ca043a51c..47d8a72c7 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/HTMLPre.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/HTMLPre.swift @@ -6,7 +6,7 @@ class HTMLPre: ParagraphProperty { super.encode(with: aCoder) } - override public class var supportsSecureCoding: Bool { true } + override open class var supportsSecureCoding: Bool { true } override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) diff --git a/Aztec/Classes/TextKit/ParagraphProperty/Header.swift b/Aztec/Classes/TextKit/ParagraphProperty/Header.swift index d5120720a..95ffe5cce 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/Header.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/Header.swift @@ -83,7 +83,7 @@ open class Header: ParagraphProperty { aCoder.encode(level.rawValue, forKey: Keys.level) } - override public class var supportsSecureCoding: Bool { true } + override open class var supportsSecureCoding: Bool { true } static func ==(lhs: Header, rhs: Header) -> Bool { return lhs.level == rhs.level diff --git a/Aztec/Classes/TextKit/ParagraphProperty/ParagraphProperty.swift b/Aztec/Classes/TextKit/ParagraphProperty/ParagraphProperty.swift index 79ad14b59..b4ad01a97 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/ParagraphProperty.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/ParagraphProperty.swift @@ -19,7 +19,7 @@ open class ParagraphProperty: NSObject, NSSecureCoding { public func encode(with aCoder: NSCoder) { } - public class var supportsSecureCoding: Bool { true } + open class var supportsSecureCoding: Bool { true } static func ==(lhs: ParagraphProperty, rhs: ParagraphProperty) -> Bool { return lhs === rhs diff --git a/Aztec/Classes/TextKit/ParagraphProperty/TextList.swift b/Aztec/Classes/TextKit/ParagraphProperty/TextList.swift index 904118e4e..84f9f4bac 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/TextList.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/TextList.swift @@ -84,7 +84,7 @@ open class TextList: ParagraphProperty { aCoder.encode(reversed, forKey: AttributeType.reversed.rawValue) } - override public class var supportsSecureCoding: Bool { true } + override open class var supportsSecureCoding: Bool { true } public static func ==(lhs: TextList, rhs: TextList) -> Bool { return lhs.style == rhs.style && lhs.start == rhs.start && lhs.reversed == rhs.reversed diff --git a/Aztec/Classes/TextKit/ParagraphStyle.swift b/Aztec/Classes/TextKit/ParagraphStyle.swift index 87d72ece9..ad20d5838 100644 --- a/Aztec/Classes/TextKit/ParagraphStyle.swift +++ b/Aztec/Classes/TextKit/ParagraphStyle.swift @@ -112,7 +112,7 @@ open class ParagraphStyle: NSMutableParagraphStyle, CustomReflectable { aCoder.encode(headerLevel, forKey: EncodingKeys.headerLevel.rawValue) } - override public class var supportsSecureCoding: Bool { true } + override open class var supportsSecureCoding: Bool { true } override open func setParagraphStyle(_ baseParagraphStyle: NSParagraphStyle) { diff --git a/Aztec/Classes/TextKit/VideoAttachment.swift b/Aztec/Classes/TextKit/VideoAttachment.swift index 89e82c994..b3e0dd3c9 100644 --- a/Aztec/Classes/TextKit/VideoAttachment.swift +++ b/Aztec/Classes/TextKit/VideoAttachment.swift @@ -43,7 +43,7 @@ open class VideoAttachment: MediaAttachment { } } - override public class var supportsSecureCoding: Bool { true } + override open class var supportsSecureCoding: Bool { true } /// Required Initializer /// diff --git a/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift b/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift index 655d2887c..606571b4f 100644 --- a/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift +++ b/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift @@ -11,6 +11,6 @@ class Gutenblock: ParagraphProperty { super.init(coder: aDecoder) } - override public class var supportsSecureCoding: Bool { true } + override open class var supportsSecureCoding: Bool { true } } From 83e548fbfbce022fb48d800831f3ba91e581f466 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Fri, 19 Apr 2024 16:07:24 +0200 Subject: [PATCH 16/17] Simpler code style on UIPasteboard+Helpers > UTType --- .../Extensions/UIPasteboard+Helpers.swift | 72 ++++++++----------- 1 file changed, 30 insertions(+), 42 deletions(-) diff --git a/Aztec/Classes/Extensions/UIPasteboard+Helpers.swift b/Aztec/Classes/Extensions/UIPasteboard+Helpers.swift index 47c9816b3..bc7d9c651 100644 --- a/Aztec/Classes/Extensions/UIPasteboard+Helpers.swift +++ b/Aztec/Classes/Extensions/UIPasteboard+Helpers.swift @@ -44,58 +44,46 @@ extension UIPasteboard { let identifier: String static let html: UTType = { - UTType(identifier: { - if #available(iOS 14.0, *) { - UniformTypeIdentifiers.UTType.html.identifier - } else { - kUTTypeHTML as String - } - }()) + if #available(iOS 14.0, *) { + UTType(identifier: UniformTypeIdentifiers.UTType.html.identifier) + } else { + UTType(identifier: kUTTypeHTML as String) + } }() static let plainText: UTType = { - UTType(identifier: { - if #available(iOS 14.0, *) { - UniformTypeIdentifiers.UTType.utf8PlainText.identifier - } else { - kUTTypeUTF8PlainText as String - } - }()) + if #available(iOS 14.0, *) { + UTType(identifier: UniformTypeIdentifiers.UTType.utf8PlainText.identifier) + } else { + UTType(identifier: kUTTypeUTF8PlainText as String) + } }() static let richText: UTType = { - UTType(identifier: { - if #available(iOS 14.0, *) { - UniformTypeIdentifiers.UTType.text.identifier - } else { - kUTTypeText as String - } - }()) + if #available(iOS 14.0, *) { + UTType(identifier: UniformTypeIdentifiers.UTType.text.identifier) + } else { + UTType(identifier: kUTTypeText as String) + } }() static let RTFText: UTType = { - UTType(identifier: { - if #available(iOS 14.0, *) { - UniformTypeIdentifiers.UTType.rtf.identifier - } else { - kUTTypeRTF as String - } - }()) + if #available(iOS 14.0, *) { + UTType(identifier: UniformTypeIdentifiers.UTType.rtf.identifier) + } else { + UTType(identifier: kUTTypeRTF as String) + } }() static let RTFDText: UTType = { - UTType(identifier: { - if #available(iOS 14.0, *) { - UniformTypeIdentifiers.UTType.flatRTFD.identifier - } else { - kUTTypeFlatRTFD as String - } - }()) + if #available(iOS 14.0, *) { + UTType(identifier: UniformTypeIdentifiers.UTType.flatRTFD.identifier) + } else { + UTType(identifier: kUTTypeFlatRTFD as String) + } }() static let URL: UTType = { - UTType(identifier: { - if #available(iOS 14.0, *) { - UniformTypeIdentifiers.UTType.url.identifier - } else { - kUTTypeURL as String - } - }()) + if #available(iOS 14.0, *) { + UTType(identifier: UniformTypeIdentifiers.UTType.url.identifier) + } else { + UTType(identifier: kUTTypeURL as String) + } }() } From ce0726e153ff00d44c9adb69a7972f9171998cbd Mon Sep 17 00:00:00 2001 From: Gerardo Date: Tue, 21 May 2024 17:00:25 +0200 Subject: [PATCH 17/17] Fix shorcode test by using an attribute with key-value --- .../CaptionShortcodeInputProcessorTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPressEditor/WordPressEditorTests/WordPressPlugin/Calypso/CaptionShortcode/CaptionShortcodeInputProcessorTests.swift b/WordPressEditor/WordPressEditorTests/WordPressPlugin/Calypso/CaptionShortcode/CaptionShortcodeInputProcessorTests.swift index d185ced69..bbc112a3c 100644 --- a/WordPressEditor/WordPressEditorTests/WordPressPlugin/Calypso/CaptionShortcode/CaptionShortcodeInputProcessorTests.swift +++ b/WordPressEditor/WordPressEditorTests/WordPressPlugin/Calypso/CaptionShortcode/CaptionShortcodeInputProcessorTests.swift @@ -18,8 +18,8 @@ class CaptionShortcodeInputProcessorTests: XCTestCase { /// Verifies that a caption shortcode wrapping [Image + Text + Multiple Line Breaks] is properly processed. /// func testCaptionShortcodeIsProperlyConvertedIntoFigureTagPreservingNestedTags() { - let input = "[caption someattribute]Text


[/caption]" - let expected = "
Text


" + let input = "[caption someattribute=\"value\"]Text


[/caption]" + let expected = "
Text


" XCTAssertEqual(processor.process(input), expected) }