From 1455c84b0ccf8ea874280576821cb721260f89b2 Mon Sep 17 00:00:00 2001 From: loner <2788892716@qq.com> Date: Fri, 10 Oct 2025 05:16:43 +0800 Subject: [PATCH] fix(tray): Improving regex escaping logic. --- Modules/Bar/Widgets/Tray.qml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Modules/Bar/Widgets/Tray.qml b/Modules/Bar/Widgets/Tray.qml index 8361a1d6..88bd9f6b 100644 --- a/Modules/Bar/Widgets/Tray.qml +++ b/Modules/Bar/Widgets/Tray.qml @@ -41,7 +41,28 @@ Rectangle { property var filteredItems: [] function wildCardMatch(str, rule) { - return str.toLowerCase().includes(rule.toLowerCase()); // Simple substring match + if (!str || !rule) { + return false; + } + Logger.log("Tray", "wildCardMatch - Input str:", str, "rule:", rule); + + // Escape all special regex characters in the rule + let escapedRule = rule.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + // Convert '*' to '.*' for wildcard matching + let pattern = escapedRule.replace(/\\\*/g, '.*'); + // Add ^ and $ to match the entire string + pattern = '^' + pattern + '$'; + + Logger.log("Tray", "wildCardMatch - Generated pattern:", pattern); + + try { + const regex = new RegExp(pattern, 'i'); // 'i' for case-insensitive + Logger.log("Tray", "wildCardMatch - Regex test result:", regex.test(str)); + return regex.test(str); + } catch (e) { + Logger.warn("Tray", "Invalid regex pattern for wildcard match:", rule, e.message); + return false; // If regex is invalid, it won't match + } } function updateFilteredItems() {