Skip to content

Commit 2bdc7f0

Browse files
Andrea Barbassoatarix83
authored andcommitted
Merged in task/ux-plus-2023_02_x/UXP-267 (pull request #67)
[UXP-267] fix html sanitization Approved-by: Francesco Molinaro
2 parents bd2d8d3 + a8a0b04 commit 2bdc7f0

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,27 @@ describe('MarkdownEditorComponent', () => {
4040

4141
});
4242

43+
describe('editValue setter', () => {
44+
it('should set _editValue when value is provided and _editValue is empty', () => {
45+
component.editValue = 'Initial Value';
46+
expect(component.editValue).toBe('Initial Value');
47+
});
48+
49+
it('should not overwrite _editValue if it is already set', () => {
50+
component.editValue = 'Existing Value';
51+
component.editValue = 'New Value';
52+
expect(component.editValue).toBe('Existing Value');
53+
});
54+
55+
it('should handle null value gracefully', () => {
56+
component.editValue = null;
57+
expect(component.editValue).toBe('');
58+
});
59+
60+
it('should handle empty string value gracefully', () => {
61+
component.editValue = '';
62+
expect(component.editValue).toBe('');
63+
});
64+
});
65+
4366
});

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,26 @@ import { DomSanitizer } from '@angular/platform-browser';
88
templateUrl: './markdown-editor.component.html',
99
styleUrls: ['./markdown-editor.component.scss']
1010
})
11-
export class MarkdownEditorComponent {
11+
export class MarkdownEditorComponent {
1212
/**
1313
* Markdown Editor String value
1414
*/
15-
@Input() editValue = '';
15+
@Input() set editValue(value: string) {
16+
if (value && !this._editValue) {
17+
this._editValue = value;
18+
}
19+
}
20+
21+
get editValue(): string {
22+
return this._editValue;
23+
}
24+
25+
private _editValue = '';
26+
/**
27+
* Indicates whether the markdown editor is required.
28+
*/
29+
@Input() required: boolean;
30+
1631
/**
1732
* Markdown Editor String value Emitter
1833
*/
@@ -24,7 +39,7 @@ export class MarkdownEditorComponent {
2439
modules: QuillModules = {
2540
'emoji-toolbar': true,
2641
toolbar: {
27-
container: [
42+
container: [
2843
['bold', 'italic', 'underline', 'strike'],
2944
[{ 'header': 1 }, { 'header': 2 }],
3045
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
@@ -50,6 +65,7 @@ export class MarkdownEditorComponent {
5065
*/
5166
updateContent(content: ContentChange) {
5267
const sanitizedContent = this.sanitizer.sanitize(SecurityContext.HTML, content.html);
53-
this.editValueChange.emit(sanitizedContent);
68+
const normalizedContent = sanitizedContent?.replace(/ /g, ' ');
69+
this.editValueChange.emit(normalizedContent);
5470
}
5571
}

0 commit comments

Comments
 (0)