From 358e658459668f17800d5cd121e2f35064608d35 Mon Sep 17 00:00:00 2001 From: Will Miao Date: Tue, 3 Feb 2026 15:42:09 +0800 Subject: [PATCH] fix(trigger_word_toggle): add trigger word normalization method Introduce a new private method `_normalize_trigger_words` to handle consistent splitting and cleaning of trigger word strings. This method splits input by both single and double commas, strips whitespace, and filters out empty strings, returning a set of normalized words. It is now used in `process_trigger_words` to compare trigger word overrides, ensuring accurate detection of changes by comparing normalized sets instead of raw strings. --- py/nodes/trigger_word_toggle.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/py/nodes/trigger_word_toggle.py b/py/nodes/trigger_word_toggle.py index e2e225f6..58a7062a 100644 --- a/py/nodes/trigger_word_toggle.py +++ b/py/nodes/trigger_word_toggle.py @@ -60,6 +60,22 @@ class TriggerWordToggleLM: else: return data + def _normalize_trigger_words(self, trigger_words): + """Normalize trigger words by splitting by both single and double commas, stripping whitespace, and filtering empty strings""" + if not trigger_words or not isinstance(trigger_words, str): + return set() + + # Split by double commas first to preserve groups, then by single commas + groups = re.split(r",{2,}", trigger_words) + words = [] + for group in groups: + # Split each group by single comma + group_words = [word.strip() for word in group.split(",")] + words.extend(group_words) + + # Filter out empty strings and return as set + return set(word for word in words if word) + def process_trigger_words( self, id, @@ -81,7 +97,7 @@ class TriggerWordToggleLM: if ( trigger_words_override and isinstance(trigger_words_override, str) - and trigger_words_override != trigger_words + and self._normalize_trigger_words(trigger_words_override) != self._normalize_trigger_words(trigger_words) ): filtered_triggers = trigger_words_override return (filtered_triggers,)