Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Escape HTML in markdown. * Escape variables for message history. * Rename escape method.
- Loading branch information
1 parent
16fc031
commit cf4efc5
Showing
23 changed files
with
315 additions
and
113 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
89 changes: 89 additions & 0 deletions
89
frontend/src/app/framework/angular/markdown.directive.spec.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Squidex Headless CMS | ||
* | ||
* @license | ||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. | ||
*/ | ||
|
||
import { Renderer2 } from '@angular/core'; | ||
import { IMock, It, Mock, Times } from 'typemoq'; | ||
import { MarkdownDirective } from './markdown.directive'; | ||
|
||
describe('MarkdownDirective', () => { | ||
let renderer: IMock<Renderer2>; | ||
let markdownElement = {}; | ||
let markdownDirective: MarkdownDirective; | ||
|
||
beforeEach(() => { | ||
renderer = Mock.ofType<Renderer2>(); | ||
|
||
markdownElement = {}; | ||
markdownDirective = new MarkdownDirective(markdownElement as any, renderer.object); | ||
}); | ||
|
||
it('should render empty text as text', () => { | ||
markdownDirective.markdown = ''; | ||
markdownDirective.ngOnChanges(); | ||
|
||
verifyTextRender(''); | ||
}); | ||
|
||
it('should render as text if result has no tags', () => { | ||
markdownDirective.inline = true; | ||
markdownDirective.markdown = 'markdown'; | ||
markdownDirective.ngOnChanges(); | ||
|
||
verifyTextRender('markdown'); | ||
}); | ||
|
||
it('should render as text if optional', () => { | ||
markdownDirective.optional = true; | ||
markdownDirective.markdown = '**bold**'; | ||
markdownDirective.ngOnChanges(); | ||
|
||
verifyTextRender('**bold**'); | ||
}); | ||
|
||
it('should render if optional with exclamation', () => { | ||
markdownDirective.optional = true; | ||
markdownDirective.markdown = '!**bold**'; | ||
markdownDirective.ngOnChanges(); | ||
|
||
verifyHtmlRender('<strong>bold</strong>'); | ||
}); | ||
|
||
it('should render as HTML if allowed', () => { | ||
markdownDirective.inline = false; | ||
markdownDirective.markdown = '**bold**'; | ||
markdownDirective.ngOnChanges(); | ||
|
||
verifyHtmlRender('<p><strong>bold</strong></p>\n'); | ||
}); | ||
|
||
it('should render as inline HTML if allowed', () => { | ||
markdownDirective.markdown = '!**bold**'; | ||
markdownDirective.ngOnChanges(); | ||
|
||
verifyHtmlRender('<strong>bold</strong>'); | ||
}); | ||
|
||
it('should render HTML escaped', () => { | ||
markdownDirective.inline = false; | ||
markdownDirective.markdown = '<h1>Header</h1>'; | ||
markdownDirective.ngOnChanges(); | ||
|
||
verifyHtmlRender('<p><h1>Header</h1></p>\n'); | ||
}); | ||
|
||
function verifyTextRender(text: string) { | ||
renderer.verify(x => x.setProperty(It.isAny(), 'textContent', text), Times.once()); | ||
|
||
expect().nothing(); | ||
} | ||
|
||
function verifyHtmlRender(text: string) { | ||
renderer.verify(x => x.setProperty(It.isAny(), 'innerHTML', text), Times.once()); | ||
|
||
expect().nothing(); | ||
} | ||
}); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.