diff --git a/packages/pipes/src/balHighlight.spec.ts b/packages/pipes/src/balHighlight.spec.ts index 397216f..81acfee 100755 --- a/packages/pipes/src/balHighlight.spec.ts +++ b/packages/pipes/src/balHighlight.spec.ts @@ -18,4 +18,14 @@ describe('balHighlight', () => { `Vertrag`, ) }) + test('should return the same text without highlighting when searching <', () => { + expect(balHighlight(`Vertrag`, '<')).toBe( + `Vertrag`, + ) + }) + test('should return the same text without highlighting when searching html props', () => { + expect(balHighlight(`Vertrag`, 'font-weight')).toBe( + `Vertrag`, + ) + }) }) diff --git a/packages/pipes/src/balHighlight.ts b/packages/pipes/src/balHighlight.ts index 92069e0..e2ddd46 100755 --- a/packages/pipes/src/balHighlight.ts +++ b/packages/pipes/src/balHighlight.ts @@ -7,7 +7,7 @@ */ export function balHighlight(value: string, search: string, cssClass = 'bal-highlight'): string { if (search && value) { - const hrefTag = '(href="[^>]+")|(' + const hrefTag = '(<(.*?)>)|(' let pattern = hrefTag.concat(search.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')).concat(')') pattern = pattern .split(' ') @@ -17,7 +17,7 @@ export function balHighlight(value: string, search: string, cssClass = 'bal-high .join('|') const regex = new RegExp(pattern, 'gi') return value.replace(regex, match => { - return match.includes('href') ? match : `${match}` + return match.includes('<') && match.includes('>') ? match : `${match}` }) } else { return value