Skip to content

Commit

Permalink
[ACS-5395] Fixed possibility to containing script by string (#8696)
Browse files Browse the repository at this point in the history
* ACS-5395 Fixed possibility to containing script by string

* ACS-5395 Fixed possibility to containing script by string
  • Loading branch information
AleksanderSklorz committed Jun 27, 2023
1 parent 1078e27 commit be896b5
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
* limitations under the License.
*/

import { Injectable } from '@angular/core';
import { Injectable, SecurityContext } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';

export interface HighlightTransformResult {
text: string;
Expand All @@ -27,6 +28,8 @@ export interface HighlightTransformResult {
})
export class HighlightTransformService {

constructor(private sanitizer: DomSanitizer) {}

/**
* Searches for `search` string(s) within `text` and highlights all occurrences.
*
Expand All @@ -44,7 +47,7 @@ export class HighlightTransformService {
pattern = pattern.split(' ').filter((t) => t.length > 0).join('|');

const regex = new RegExp(pattern, 'gi');
result = text.replace(/<[^>]+>/g, '').replace(regex, (match) => {
result = this.sanitizer.sanitize(SecurityContext.HTML, text).replace(regex, (match) => {
isMatching = true;
return `<span class="${wrapperClass}">${match}</span>`;
});
Expand Down

0 comments on commit be896b5

Please sign in to comment.