From 36a9659e434270399f0640a7177bfb3c1aab7d6a Mon Sep 17 00:00:00 2001 From: Klayton Erekson Date: Thu, 28 Nov 2024 21:11:05 -0500 Subject: [PATCH 1/3] Update StickerSet.swift --- Source/StickerSet.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/StickerSet.swift b/Source/StickerSet.swift index 69b54c5..9feee10 100644 --- a/Source/StickerSet.swift +++ b/Source/StickerSet.swift @@ -130,10 +130,18 @@ public class StickerSet { if emojis.isEmpty { throw StickersError.emojiIsEmpty } + if !arrayContainsEmoji(array: emojis) { + throw StickersError.emojisInvalid + } if try self.validateData(data) { self.stickers.append(Sticker(data: data, emojis: emojis)) } } + + /// Returns true if an array contains at least 1 valid emoji + func arrayContainsEmoji(array: [String]) -> Bool { + return array.contains { $0.containsEmoji } + } /** Sets a thumbnail of the sticker set using the provided data. From 49c5d093896d8bc03393cadcf9178aeb522e8dda Mon Sep 17 00:00:00 2001 From: Klayton Erekson Date: Thu, 28 Nov 2024 21:12:44 -0500 Subject: [PATCH 2/3] Create StringExtension.swift --- Source/StringExtension.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Source/StringExtension.swift diff --git a/Source/StringExtension.swift b/Source/StringExtension.swift new file mode 100644 index 0000000..7c25c75 --- /dev/null +++ b/Source/StringExtension.swift @@ -0,0 +1,11 @@ +extension String { + /// Checks if a string is a valid emoji + var containsEmoji: Bool { + for scalar in self.unicodeScalars { + if scalar.properties.isEmoji && (scalar.value > 0x238C) { // Exclude non-graphical symbols + return true + } + } + return false + } +} From 16915da37f0caf20d1e7443c693c005296182a21 Mon Sep 17 00:00:00 2001 From: Klayton Erekson Date: Thu, 28 Nov 2024 21:13:07 -0500 Subject: [PATCH 3/3] Update Errors.swift --- Source/Errors.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Errors.swift b/Source/Errors.swift index 815ae6b..3f9e8d3 100644 --- a/Source/Errors.swift +++ b/Source/Errors.swift @@ -8,5 +8,6 @@ public enum StickersError: Error { case dataTypeMismatch case setIsEmpty case emojiIsEmpty + case emojisInvalid case telegramNotInstalled }