Skip to content

Commit

Permalink
more html entities to unescape by default (#1538)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Jul 27, 2022
1 parent 85857b2 commit f91903b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
12 changes: 11 additions & 1 deletion 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 = {
'&': '&',
Expand All @@ -11,6 +13,14 @@ const htmlEntities = {
''': "'",
'"': '"',
'"': '"',
' ': ' ',
' ': ' ',
'©': '©',
'©': '©',
'®': '®',
'®': '®',
'…': '…',
'…': '…',
};

const unescapeHtmlEntity = (m) => htmlEntities[m];
Expand Down
2 changes: 1 addition & 1 deletion test/trans.render.spec.js
Expand Up @@ -636,7 +636,7 @@ describe('trans should allow escaped html', () => {
<a
href="/msgs"
>
&lt;&nbsp;&&gt;
&lt; &&gt;
</a>
.
</div>
Expand Down
11 changes: 11 additions & 0 deletions test/unescape.spec.js
@@ -0,0 +1,11 @@
import { unescape } from '../src/unescape';

describe('unescape', () => {
it('should correctly unescape', () => {
const unescaped = unescape(
'&amp; &#38; &lt; &#60; &gt; &#62; &apos; &#39; &quot; &#34; &nbsp; &#160; &copy; &#169; &reg; &#174; &hellip; &#8230;',
);

expect(unescaped).toEqual('& & < < > > \' \' " " © © ® ® … …');
});
});

0 comments on commit f91903b

Please sign in to comment.