Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more html entities to unescape by default #1538

Merged
merged 1 commit into from Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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('& & < < > > \' \' " " © © ® ® … …');
});
});