From 9d559871125b14218f3fdbcc82225be2d0560e1a Mon Sep 17 00:00:00 2001 From: wusamzong Date: Wed, 29 Nov 2023 10:38:24 +0800 Subject: [PATCH] deal with doupache's suggestion --- src/app/components/nodes-view/highlighttable-search.pipe.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/components/nodes-view/highlighttable-search.pipe.ts b/src/app/components/nodes-view/highlighttable-search.pipe.ts index 21fe56d8..7397a139 100644 --- a/src/app/components/nodes-view/highlighttable-search.pipe.ts +++ b/src/app/components/nodes-view/highlighttable-search.pipe.ts @@ -6,7 +6,11 @@ import { Pipe, PipeTransform } from '@angular/core'; export class HighlightSearchPipe implements PipeTransform { transform(value: string, search: string): string { - const valueStr = value + ''; // Ensure numeric values are converted to strings + const valueStr = String(value); // Ensure numeric values are converted to strings + // (?![^&;]+;) - to ensure that there are no HTML entities (such as & or <) + // ex. value = "<span>" search = "span", The word 'span' will not be included in the matches + // (?!<[^<>]*) - to ensure that there are no HTML tags (<...>) + // ex. value = "" search = "span", The word 'span' will not be included in the matches return valueStr.replace(new RegExp('(?![^&;]+;)(?!<[^<>]*)(' + search + ')(?![^<>]*>)(?![^&;]+;)', 'gi'), '$1'); }