diff options
author | Maciek Baron <thebezet@gmail.com> | 2018-07-05 11:19:38 +0100 |
---|---|---|
committer | Yamagishi Kazutoshi <ykzts@desire.sh> | 2018-07-05 19:19:38 +0900 |
commit | 1e65cdf8213f9da93d97f363bef2d6104278e542 (patch) | |
tree | 53973554ff050903ad2750e62e62a6f6fafc4ff2 /app/javascript | |
parent | cdfe51e3253edc219116e9276f9416cda95c4461 (diff) |
Add comment, test to unescapeHTML (#7949)
Diffstat (limited to 'app/javascript')
-rw-r--r-- | app/javascript/mastodon/utils/__tests__/html-test.js | 10 | ||||
-rw-r--r-- | app/javascript/mastodon/utils/html.js | 1 |
2 files changed, 11 insertions, 0 deletions
diff --git a/app/javascript/mastodon/utils/__tests__/html-test.js b/app/javascript/mastodon/utils/__tests__/html-test.js new file mode 100644 index 000000000..ef9296e6c --- /dev/null +++ b/app/javascript/mastodon/utils/__tests__/html-test.js @@ -0,0 +1,10 @@ +import * as html from '../html'; + +describe('html', () => { + describe('unsecapeHTML', () => { + it('returns unescaped HTML', () => { + const output = html.unescapeHTML('<p>lorem</p><p>ipsum</p><br><br>'); + expect(output).toEqual('lorem\n\nipsum\n<br>'); + }); + }); +}); diff --git a/app/javascript/mastodon/utils/html.js b/app/javascript/mastodon/utils/html.js index 5159df9db..247e98c88 100644 --- a/app/javascript/mastodon/utils/html.js +++ b/app/javascript/mastodon/utils/html.js @@ -1,3 +1,4 @@ +// NB: This function can still return unsafe HTML export const unescapeHTML = (html) => { const wrapper = document.createElement('div'); wrapper.innerHTML = html.replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n').replace(/<[^>]*>/g, ''); |