Skip to content

Commit

Permalink
Handle regex syntax error for torrent filtering by showing 0 torrents q…
Browse files Browse the repository at this point in the history
  • Loading branch information
HamletDuFromage committed Aug 8, 2024
1 parent bee56f2 commit 7688765
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/webui/www/private/scripts/dynamicTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1502,9 +1502,19 @@ window.qBittorrent.DynamicTable ??= (() => {
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 = null;
if (filterText.length > 0) {
if (useRegex) {
try {
filterTerms = new RegExp(filterText);
} catch (e) {
console.error(`Invalid regex pattern: ${filterText}`);
return filteredRows;
}
} else {
filterTerms = filterText.split(" ");
}
}

for (let i = 0; i < rows.length; ++i) {
if (this.applyFilter(rows[i], selected_filter, selected_category, selectedTag, selectedTracker, filterTerms)) {
Expand Down

0 comments on commit 7688765

Please sign in to comment.