summaryrefslogtreecommitdiff
path: root/html
diff options
context:
space:
mode:
authorPhilip Kaludercic <philipk@posteo.net>2024-02-25 17:51:06 +0100
committerPhilip Kaludercic <philipk@posteo.net>2024-02-25 21:37:29 +0100
commit7247f047a34e263cb198014c1438d5fca7049168 (patch)
treeb6c4504b997e73c67e7bae91eb57198b1e0c9d46 /html
parentf56a985ab0a321ed09291f788abf56f5741dbf69 (diff)
Improve robustness of table filter
To avoid raising an exception while parsing a regular expression, we process the input escaping meta-characters and creating a custom regular expression that matches words in the query occurring in any order. (Bug#69132)
Diffstat (limited to 'html')
-rw-r--r--html/javascript/package-search.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/html/javascript/package-search.js b/html/javascript/package-search.js
index af5d482..78df7f2 100644
--- a/html/javascript/package-search.js
+++ b/html/javascript/package-search.js
@@ -14,6 +14,12 @@
"use strict";
+function parse_pattern(pattern) { // ala `apropos-parse-pattern'
+ const words = pattern.split(/\s+/);
+ const parts = words.map(s => `(${s.replace(/([^a-zA-Z0-9])/g, "\\$1")})`);
+ return new RegExp(`((${parts.join("|")}).*)+`, "i");
+}
+
window.addEventListener("load", function (event) {
const table = document.getElementById("packages");
@@ -26,7 +32,7 @@ window.addEventListener("load", function (event) {
if (tid) clearTimeout(tid);
tid = setTimeout(function (query) {
- const pattern = new RegExp(query);
+ const pattern = parse_pattern(query);
for (let i = 1; i < table.rows.length; i++) {
const row = table.rows.item(i);