diff --git a/src/unescape.js b/src/unescape.js index 1b01a2b1..38d50bf3 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 ec9cb915..55306215 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 00000000..07141adb --- /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('& & < < > > \' \' " " © © ® ® … …'); + }); +});