Created
January 29, 2018 22:45
-
-
Save chaitanya1248/520b6c21c1445f24fcbc0e65fd53661f to your computer and use it in GitHub Desktop.
doc-preview component to sanitize src
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Component, Input} from '@angular/core'; | |
import { DomSanitizer, SafeHtml } from '@angular/platform-browser'; | |
import {DOMPurify} from 'dompurify'; | |
@Component({ | |
selector: 'tb-doc-preview', | |
template: '' | |
}) | |
export class TbDocPreviewComponent { | |
@Input() public document: String; | |
constructor(private sanitizer: DomSanitizer) { | |
} | |
get processedDocument(): SafeHtml { | |
console.log('document received into getProcessedDocument', document); | |
if (this.document) { | |
const sanitized = DOMPurify.sanitize(this.document, {FORBID_TAGS: ['script'], RETURN_DOM: true}); | |
const script = document.createElement('script'); | |
script.src = 'assets/js/iframeResizer.contentWindow.js'; | |
sanitized.appendChild(script); | |
/* Return result */ | |
return this.sanitizer.bypassSecurityTrustHtml(sanitized.outerHTML); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment