Merge pull request #66 from andrewjanssen/fix-regex-exception

Search fails on invalid regex
This commit is contained in:
Abdenasser Elidrissi 2024-11-08 19:38:20 +01:00 committed by GitHub
commit 01bda83910
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View File

@ -26,7 +26,7 @@
Search for processes by name, command, or PID. Search for multiple things at once by separating them with commas. For Search for processes by name, command, or PID. Search for multiple things at once by separating them with commas. For
example, `arm, x86` will return processes having `arm` or `x86` as a substring of the name or command. You can use example, `arm, x86` will return processes having `arm` or `x86` as a substring of the name or command. You can use
regular expressions too. For example, `d$` will return a list of daemons (which tend to end in the letter `d`), while regular expressions too. For example, `d$` will return a list of daemons (which tend to end in the letter `d`), while
`(\w+)\.\w+` will return a list of processes with reverse domain name notation, such as `com.docker.vmnetd`. `^(\w+\.)+\w+$` will return a list of processes with reverse domain name notation, such as `com.docker.vmnetd`.
- 📌 Pin important processes - 📌 Pin important processes
- 🛠 Process management (kill processes) - 🛠 Process management (kill processes)

View File

@ -68,7 +68,13 @@
const nameSubstringMatch = process.name const nameSubstringMatch = process.name
.toLowerCase() .toLowerCase()
.includes(term.toLowerCase()); .includes(term.toLowerCase());
const nameRegexMatch = new RegExp(term, "i").test(process.name); const nameRegexMatch = (() => {
try {
return new RegExp(term, "i").test(process.name);
} catch {
return false;
}
})();
const commandMatch = process.command const commandMatch = process.command
.toLowerCase() .toLowerCase()
.includes(term.toLowerCase()); .includes(term.toLowerCase());