From 1e65cdf8213f9da93d97f363bef2d6104278e542 Mon Sep 17 00:00:00 2001 From: Maciek Baron Date: Thu, 5 Jul 2018 11:19:38 +0100 Subject: [PATCH] Add comment, test to unescapeHTML (#7949) --- app/javascript/mastodon/utils/__tests__/html-test.js | 10 ++++++++++ app/javascript/mastodon/utils/html.js | 1 + 2 files changed, 11 insertions(+) create mode 100644 app/javascript/mastodon/utils/__tests__/html-test.js 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 0000000000..ef9296e6c3 --- /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('

lorem

ipsum


<br>'); + expect(output).toEqual('lorem\n\nipsum\n
'); + }); + }); +}); diff --git a/app/javascript/mastodon/utils/html.js b/app/javascript/mastodon/utils/html.js index 5159df9db7..247e98c88a 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(//g, '\n').replace(/<\/p>

/g, '\n\n').replace(/<[^>]*>/g, '');