From 9a8572bd215eead276afc189c9a35d6d3baba433 Mon Sep 17 00:00:00 2001 From: HamletDuFromage <61667930+HamletDuFromage@users.noreply.github.com> Date: Mon, 12 Aug 2024 08:54:37 +0200 Subject: [PATCH] WebUI: Handle regex syntax error for torrent filtering https://github.com/qbittorrent/qBittorrent/pull/20566#discussion_r1704548226 PR #21173. --- src/webui/www/private/scripts/dynamicTable.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/webui/www/private/scripts/dynamicTable.js b/src/webui/www/private/scripts/dynamicTable.js index e68f2398c..246b237b0 100644 --- a/src/webui/www/private/scripts/dynamicTable.js +++ b/src/webui/www/private/scripts/dynamicTable.js @@ -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]);