[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] main 7247f047a3 2/2: Improve robustness of table filter
From: |
Philip Kaludercic |
Subject: |
[elpa] main 7247f047a3 2/2: Improve robustness of table filter |
Date: |
Sun, 25 Feb 2024 15:37:56 -0500 (EST) |
branch: main
commit 7247f047a34e263cb198014c1438d5fca7049168
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
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)
---
html/javascript/package-search.js | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/html/javascript/package-search.js
b/html/javascript/package-search.js
index af5d48230a..78df7f2f24 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);