From c15291f5d80919e8cf569b430d435bef6220376d Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Wed, 16 Mar 2022 11:06:21 +0100 Subject: [PATCH] Escape strings for use in regex search. --- docs/index.html | 8 +++++++- examples/index.html | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/index.html b/docs/index.html index f65726b1121f2a..f9a69704cbbcc7 100644 --- a/docs/index.html +++ b/docs/index.html @@ -350,6 +350,12 @@

three.js

} + function escapeRegExp( string ) { + + return string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ); // https://stackoverflow.com/a/6969486/5250847 + + } + function updateFilter() { let v = filterInput.value.trim(); @@ -367,7 +373,7 @@

three.js

// - const regExp = new RegExp( filterInput.value, 'gi' ); + const regExp = new RegExp( escapeRegExp( v ), 'gi' ); for ( let pageName in pageProperties ) { diff --git a/examples/index.html b/examples/index.html index 29b09bd49ba4df..6c1a11cdc57ab3 100644 --- a/examples/index.html +++ b/examples/index.html @@ -249,6 +249,12 @@

three.js

} + function escapeRegExp( string ) { + + return string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ); // https://stackoverflow.com/a/6969486/5250847 + + } + function updateFilter( files, tags ) { let v = filterInput.value.trim(); @@ -264,7 +270,7 @@

three.js

} - const exp = new RegExp( v, 'gi' ); + const exp = new RegExp( escapeRegExp( v ), 'gi' ); for ( const key in files ) {