From 51d8baa1765de15b9e45c4e075193e1b8853f9b6 Mon Sep 17 00:00:00 2001 From: Evan Greer Date: Tue, 14 May 2024 10:54:08 -0600 Subject: [PATCH 1/2] updates execute action logic to check allowed protocols before handlers --- swift-sdk/Internal/ActionRunner.swift | 30 ++++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/swift-sdk/Internal/ActionRunner.swift b/swift-sdk/Internal/ActionRunner.swift index 409760a5f..0ec4a38cd 100644 --- a/swift-sdk/Internal/ActionRunner.swift +++ b/swift-sdk/Internal/ActionRunner.swift @@ -29,23 +29,29 @@ struct ActionRunner { customActionHandler: CustomActionHandler? = nil, urlOpener: UrlOpenerProtocol? = nil, allowedProtocols: [String] = []) -> Bool { - let handled = callExternalHandlers(action: action, - from: context.source, - urlHandler: urlHandler, - customActionHandler: customActionHandler) - if handled { - return true - } else { - if case let .openUrl(url) = detectActionType(fromAction: action), - shouldOpenUrl(url: url, from: context.source, withAllowedProtocols: allowedProtocols), - let urlOpener = urlOpener { - urlOpener.open(url: url) + if case let .openUrl(url) = detectActionType(fromAction: action), shouldOpenUrl(url: url, from: context.source, withAllowedProtocols: allowedProtocols) { + + let handled = callExternalHandlers(action: action, + from: context.source, + urlHandler: urlHandler, + customActionHandler: customActionHandler) + if handled { return true } else { - return false + if case let .openUrl(url) = detectActionType(fromAction: action), + let urlOpener = urlOpener { + urlOpener.open(url: url) + return true + } else { + return false + } } + + } else { + return false } + } // MARK: - Private From 78f8b93ba010434c5cb66ec0bfe739c53a3fd4a7 Mon Sep 17 00:00:00 2001 From: Evan Greer Date: Tue, 14 May 2024 13:20:55 -0600 Subject: [PATCH 2/2] refactors action runner --- swift-sdk/Internal/ActionRunner.swift | 37 +++++++++++++-------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/swift-sdk/Internal/ActionRunner.swift b/swift-sdk/Internal/ActionRunner.swift index 0ec4a38cd..306df81e1 100644 --- a/swift-sdk/Internal/ActionRunner.swift +++ b/swift-sdk/Internal/ActionRunner.swift @@ -30,28 +30,27 @@ struct ActionRunner { urlOpener: UrlOpenerProtocol? = nil, allowedProtocols: [String] = []) -> Bool { - if case let .openUrl(url) = detectActionType(fromAction: action), shouldOpenUrl(url: url, from: context.source, withAllowedProtocols: allowedProtocols) { - - let handled = callExternalHandlers(action: action, - from: context.source, - urlHandler: urlHandler, - customActionHandler: customActionHandler) - if handled { - return true - } else { - if case let .openUrl(url) = detectActionType(fromAction: action), - let urlOpener = urlOpener { - urlOpener.open(url: url) - return true - } else { - return false - } - } - - } else { + guard case let .openUrl(url) = detectActionType(fromAction: action), + shouldOpenUrl(url: url, from: context.source, withAllowedProtocols: allowedProtocols) else { return false } + if case let handled = callExternalHandlers(action: action, + from: context.source, + urlHandler: urlHandler, + customActionHandler: customActionHandler), handled { + return true + } + + if case let .openUrl(url) = detectActionType(fromAction: action), + let urlOpener = urlOpener { + urlOpener.open(url: url) + return true + } + + return false + + } // MARK: - Private