]> cat aescling's git repositories - mastodon.git/commitdiff
Add comment, test to unescapeHTML (#7949)
authorMaciek Baron <thebezet@gmail.com>
Thu, 5 Jul 2018 10:19:38 +0000 (11:19 +0100)
committerYamagishi Kazutoshi <ykzts@desire.sh>
Thu, 5 Jul 2018 10:19:38 +0000 (19:19 +0900)
app/javascript/mastodon/utils/__tests__/html-test.js [new file with mode: 0644]
app/javascript/mastodon/utils/html.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 (file)
index 0000000..ef9296e
--- /dev/null
@@ -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>&lt;br&gt;');
+      expect(output).toEqual('lorem\n\nipsum\n<br>');
+    });
+  });
+});
index 5159df9db75bebedbf46da9edd374645f917a4c5..247e98c88a7f31f2259570ee257385b4fd0f33a9 100644 (file)
@@ -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, '');