Skip to content

Commit

Permalink
Add precondition to check UUID
Browse files Browse the repository at this point in the history
Confirm action UUIDs are valid

- lowercase alphanumeric characters (a-z, 0-9)
- hyphen (-)
- period (.)
  • Loading branch information
emorydunn committed Dec 29, 2023
1 parent be6d5c7 commit e1611f4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Sources/StreamDeck/Extensions/CharSet+DNS.swift
Original file line number Diff line number Diff line change
@@ -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: ".", "-"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e1611f4

Please sign in to comment.