WebUI: Handle regex syntax error for torrent filtering

https://github.com/qbittorrent/qBittorrent/pull/20566#discussion_r1704548226

PR #21173.
This commit is contained in:
HamletDuFromage 2024-08-12 08:54:37 +02:00 committed by GitHub
parent 04eb40376e
commit 9a8572bd21
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1527,13 +1527,19 @@ window.qBittorrent.DynamicTable ??= (() => {
getFilteredAndSortedRows: function() {
const filteredRows = [];
const rows = this.rows.getValues();
const useRegex = $("torrentsFilterRegexBox").checked;
const filterText = $("torrentsFilterInput").value.trim().toLowerCase();
const filterTerms = (filterText.length > 0)
? (useRegex ? new RegExp(filterText) : filterText.split(" "))
: null;
let filterTerms;
try {
filterTerms = (filterText.length > 0)
? (useRegex ? new RegExp(filterText) : filterText.split(" "))
: null;
}
catch (e) { // SyntaxError: Invalid regex pattern
return filteredRows;
}
const rows = this.rows.getValues();
for (let i = 0; i < rows.length; ++i) {
if (this.applyFilter(rows[i], selected_filter, selected_category, selectedTag, selectedTracker, filterTerms)) {
filteredRows.push(rows[i]);