From e1611f41398948fc9b86ef22a67909a2685b5e72 Mon Sep 17 00:00:00 2001 From: Emory Dunn Date: Fri, 29 Dec 2023 08:23:40 -0800 Subject: [PATCH] Add precondition to check UUID Confirm action UUIDs are valid - lowercase alphanumeric characters (a-z, 0-9) - hyphen (-) - period (.) --- Sources/StreamDeck/Extensions/CharSet+DNS.swift | 16 ++++++++++++++++ .../PluginManifest/PluginAction.swift | 7 +++++++ 2 files changed, 23 insertions(+) create mode 100644 Sources/StreamDeck/Extensions/CharSet+DNS.swift diff --git a/Sources/StreamDeck/Extensions/CharSet+DNS.swift b/Sources/StreamDeck/Extensions/CharSet+DNS.swift new file mode 100644 index 0000000..9932773 --- /dev/null +++ b/Sources/StreamDeck/Extensions/CharSet+DNS.swift @@ -0,0 +1,16 @@ +// +// CharSet+DNS.swift +// +// +// Created by Emory Dunn on 12/29/23. +// + +import Foundation + + +public extension CharacterSet { + static var reverseDNS = CharacterSet + .lowercaseLetters + .union(.decimalDigits) + .union(CharacterSet(arrayLiteral: ".", "-")) +} diff --git a/Sources/StreamDeck/Support Models/PluginManifest/PluginAction.swift b/Sources/StreamDeck/Support Models/PluginManifest/PluginAction.swift index 74d1e9e..453ea41 100644 --- a/Sources/StreamDeck/Support Models/PluginManifest/PluginAction.swift +++ b/Sources/StreamDeck/Support Models/PluginManifest/PluginAction.swift @@ -80,6 +80,10 @@ struct PluginAction: Codable { visibleInActionsList: Bool? = nil, userTitleEnabled: Bool? = nil, disableAutomaticStates: Bool? = nil) { + + precondition(CharacterSet(charactersIn: uuid).isSubset(of: .reverseDNS), + "The UUID must be a uniform type identifier that contains only lowercase alphanumeric characters (a-z, 0-9), hyphen (-), and period (.)") + self.name = name self.uuid = uuid self.icon = icon @@ -103,6 +107,9 @@ struct PluginAction: Codable { } init(action: any Action.Type) { + precondition(CharacterSet(charactersIn: action.uuid).isSubset(of: .reverseDNS), + "The UUID must be a uniform type identifier that contains only lowercase alphanumeric characters (a-z, 0-9), hyphen (-), and period (.)") + self.name = action.name self.uuid = action.uuid self.icon = action.icon