From 21e78ee1ad7f80f09e5993d9603822c7be570e43 Mon Sep 17 00:00:00 2001 From: Adriano Raiano Date: Wed, 27 Jul 2022 11:45:30 +0200 Subject: [PATCH] more html entities to unescape by default --- src/unescape.js | 12 +++++++++++- test/trans.render.spec.js | 2 +- test/unescape.spec.js | 11 +++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 test/unescape.spec.js diff --git a/src/unescape.js b/src/unescape.js index 1b01a2b10..38d50bf30 100644 --- a/src/unescape.js +++ b/src/unescape.js @@ -1,4 +1,6 @@ -const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g; +// unescape common html entities + +const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230);/g; const htmlEntities = { '&': '&', @@ -11,6 +13,14 @@ const htmlEntities = { ''': "'", '"': '"', '"': '"', + ' ': ' ', + ' ': ' ', + '©': '©', + '©': '©', + '®': '®', + '®': '®', + '…': '…', + '…': '…', }; const unescapeHtmlEntity = (m) => htmlEntities[m]; diff --git a/test/trans.render.spec.js b/test/trans.render.spec.js index ec9cb9150..553062157 100644 --- a/test/trans.render.spec.js +++ b/test/trans.render.spec.js @@ -636,7 +636,7 @@ describe('trans should allow escaped html', () => { - < &> + < &> . diff --git a/test/unescape.spec.js b/test/unescape.spec.js new file mode 100644 index 000000000..07141adb5 --- /dev/null +++ b/test/unescape.spec.js @@ -0,0 +1,11 @@ +import { unescape } from '../src/unescape'; + +describe('unescape', () => { + it('should correctly unescape', () => { + const unescaped = unescape( + '& & < < > > ' ' " "     © © ® ® … …', + ); + + expect(unescaped).toEqual('& & < < > > \' \' " " © © ® ® … …'); + }); +});