Skip to content

Commit 1302bf3

Browse files
[UXP-241] add html sanitize
1 parent ff38222 commit 1302bf3

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/app/shared/markdown-editor/markdown-editor.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
22
import { NO_ERRORS_SCHEMA } from '@angular/core';
33
import { RouterTestingModule } from '@angular/router/testing';
44

5-
import { By } from '@angular/platform-browser';
5+
import { By, DomSanitizer } from '@angular/platform-browser';
66

77
import { MarkdownEditorComponent } from './markdown-editor.component';
88

@@ -16,7 +16,7 @@ describe('MarkdownEditorComponent', () => {
1616
imports: [
1717
RouterTestingModule.withRoutes([]),
1818
],
19-
providers: [],
19+
providers: [DomSanitizer],
2020
schemas: [NO_ERRORS_SCHEMA]
2121
}).compileComponents();
2222
}));

src/app/shared/markdown-editor/markdown-editor.component.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'quill-emoji/dist/quill-emoji.js';
2-
import { Component, EventEmitter, Input, Output } from '@angular/core';
2+
import { Component, EventEmitter, Input, Output, SecurityContext } from '@angular/core';
33
import { ContentChange, QuillModules } from 'ngx-quill';
4+
import { DomSanitizer } from '@angular/platform-browser';
45

56
@Component({
67
selector: 'ds-markdown-editor',
@@ -40,11 +41,15 @@ export class MarkdownEditorComponent {
4041
syntax: false
4142
};
4243

44+
constructor(private sanitizer: DomSanitizer) {}
45+
46+
4347
/**
4448
* Emit content update after editing
4549
* @param content
4650
*/
4751
updateContent(content: ContentChange) {
48-
this.editValueChange.emit(content.html);
49-
}
52+
const sanitizedContent = this.sanitizer.sanitize(SecurityContext.HTML, content.html);
53+
this.editValueChange.emit(sanitizedContent);
54+
}
5055
}

0 commit comments

Comments
 (0)