From fcd2e51c45a57e64f61376f21fd4ed0be567f8f5 Mon Sep 17 00:00:00 2001 From: mattpass Date: Sun, 25 Jul 2021 19:22:41 +0100 Subject: [PATCH] Fixed filename links to work, regex find & replace bold, simpler code --- lib/multiple-results.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/multiple-results.php b/lib/multiple-results.php index d23998d..1029d59 100644 --- a/lib/multiple-results.php +++ b/lib/multiple-results.php @@ -101,7 +101,6 @@ if (true === isset($_GET['target']) && false !== strpos($_GET['target'], "filena haveMatch = true; } if ( - // TODO: Find in filenames not working with regex, see all instances of findText and $findText below true === haveMatch && -1 < targetURL.indexOf('_perms')) { if (-1 < userTarget.indexOf("selected")) { for (let j = 0; j < parent.ICEcoder.selectedFiles.length; j++) { @@ -123,23 +122,25 @@ if (true === isset($_GET['target']) && false !== strpos($_GET['target'], "filena if (-1 < targetURLElem.parentNode.parentNode.className.indexOf('pft-directory')) { continue; } + const tidiedFileName = targetURLDisplay.replace(/\|/g, "/").replace(/_perms/g, ""); resultsDisplay += '' + - targetURLDisplay.replace(/\|/g, "/").replace(/_perms/g, "") + + tidiedFileName + '\')}, 20);parent.ICEcoder.showHide(\'hide\', parent.document.getElementById(\'blackMask\'))">'; - // TODO: get this line working - resultsDisplay += - targetURLDisplay.replace(/\|/g, "/").replace(/_perms/g, "").replace(//g, "" + - parent.ICEcoder.xssClean(findText).toLowerCase() + ""); - resultsDisplay += '
'; + + + // Highlight our matches in filename via single regex () capturing group to use with $1 + const re = /()/gi; + resultsDisplay += tidiedFileName.replace(re, '$1') + '
'; + + // If replacing in filename resultsDisplay += '
' + ' ' + - targetURL.replace(/\|/g, "/").replace(/_perms/g, "").replace(//g,"")+'
'; "; selectedText = foundInSelected ? " " : ""; document.getElementById('title').innerHTML = - findText.replace(/&/g, "&").replace(/>/g, ">").replace(/ " + foundArray.length + " " + selectedText + targetName + plural; document.getElementById('results').innerHTML = resultsDisplay;