From 80a5ce3088aa5af288c86a2a9dd73295d6f037e7 Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Mon, 2 May 2022 01:05:07 +0100 Subject: [PATCH] Check array items for surrogate methods (#93) --- .../ContentBlocking/UserScripts/SurrogatesUserScript.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/BrowserServicesKit/ContentBlocking/UserScripts/SurrogatesUserScript.swift b/Sources/BrowserServicesKit/ContentBlocking/UserScripts/SurrogatesUserScript.swift index 07ef9068f..a7d5a87fa 100644 --- a/Sources/BrowserServicesKit/ContentBlocking/UserScripts/SurrogatesUserScript.swift +++ b/Sources/BrowserServicesKit/ContentBlocking/UserScripts/SurrogatesUserScript.swift @@ -145,7 +145,10 @@ open class SurrogatesUserScript: NSObject, UserScript { return "" } let instructionsRow = codeLines.removeFirst() - let pattern = instructionsRow.split(separator: " ")[0].split(separator: "/")[1] + guard let path = instructionsRow.split(separator: " ").first, + let pattern = path.split(separator: "/").last else { + return "" + } let stringifiedFunction = codeLines.joined(separator: "\n") return "surrogates['\(pattern)'] = function () {\(stringifiedFunction)}" }