mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-08-15 18:43:59 +00:00
fix(tray): Improving regex escaping logic.
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user