0

I have a pipe that uses DomSanitizer to bypass HTML. It's bypassing it. But, it converts all attributes inside the element to lower case. The pipe looks like this:

    @Pipe({
        name: 'innerHTML'
    })
    export class InnerHTMLPipe implements PipeTransform {

        constructor(private _sanitizer: DomSanitizer) { }

        transform(value: any, args?: any): SafeHtml {
            return this._sanitizer.bypassSecurityTrustHtml(value ? value : '');
        }
    }

The component that generates the string looks like this:

    <div [innerHTML]="getProgress(data) | innerHTML"></div>
    return `<span
        matTooltipPosition="above"
        matTooltip="blablabla">hello</span>`;

But the output ends up like this:

    <div>
        <span mattooltipposition="above" mattooltip="blablabla">hello</span>
    </div>

How do I prevent DomSanitizer from changing the attributes and keep the attributes intact?

ClydeFrog
  • 912
  • 1
  • 14
  • 38

1 Answers1

1

Firstly, it doesn't do that, all bypassSecurityTrustHtml does is store your string in a class property: https://github.com/angular/angular/blob/bbeac0727b8f267a47aba1ff1bcfc8cc5ca15b61/packages/platform-browser/src/security/dom_sanitization_service.ts#L204

Secondly, you cannot get Angular directives to work simply by adding them to DOM manually.

Thirdly, html is case-insensitive so it wouldn't matter in theory: Is HTML case sensitive?

waterplea
  • 3,462
  • 5
  • 31
  • 47