From 71a94bacff9b58f2fbb903be45ca4aa9edff2a1f Mon Sep 17 00:00:00 2001 From: ACTCD <101378590+ACTCD@users.noreply.github.com> Date: Thu, 22 Aug 2024 08:56:32 +0800 Subject: [PATCH] fix: make `@grant none` work correctly --- xcode/Ext-Safari/Functions.swift | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/xcode/Ext-Safari/Functions.swift b/xcode/Ext-Safari/Functions.swift index 477c8c75..18717b9f 100644 --- a/xcode/Ext-Safari/Functions.swift +++ b/xcode/Ext-Safari/Functions.swift @@ -1247,13 +1247,19 @@ func getCode(_ filenames: [String], _ isTop: Bool)-> [String: Any]? { // attempt to get all @grant value var grants = metadata["grant"] ?? [] - // remove duplicates, if any exist + if !grants.isEmpty { - grants = Array(Set(grants)) + if grants.contains("none") { + // `@grant none` takes precedence + grants = [] + } else { + // remove duplicates + grants = Array(Set(grants)) + // filter out grant values that are not in validGrant set + grants = grants.filter{validGrants.contains($0)} + } } - - // filter out grant values that are not in validGrant set - grants = grants.filter{validGrants.contains($0)} + // set GM.info data let description = metadata["description"]?[0] ?? ""