sanitize-html 1.18.4 → 1.18.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanitize-html",
3
- "version": "1.18.4",
3
+ "version": "1.18.5",
4
4
  "description": "Clean up user-submitted HTML, preserving whitelisted elements and whitelisted attributes on a per-element basis",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -411,7 +411,10 @@ function sanitizeHtml(html, options, _recursing) {
411
411
  if (typeof(s) !== 'string') {
412
412
  s = s + '';
413
413
  }
414
- return s.replace(/\&/g, '&amp;').replace(/</g, '&lt;').replace(/\>/g, '&gt;').replace(/\"/g, '&quot;');
414
+ return s.replace(/&(?![a-zA-Z0-9#]{1,7};)/g, '&amp;') // Match ampersands not part of existing HTML entity
415
+ .replace(/</g, '&lt;')
416
+ .replace(/\>/g, '&gt;')
417
+ .replace(/\"/g, '&quot;');
415
418
  }
416
419
 
417
420
  function naughtyHref(name, href) {
package/test/test.js CHANGED
@@ -748,4 +748,17 @@ describe('sanitizeHtml', function() {
748
748
  allowedSchemes: sanitizeHtml.defaults.allowedSchemes.concat([ 'tel' ]),
749
749
  }), '<q cite=\"http://www.google.com\">HTTP</q><q cite=\"https://www.google.com\">HTTPS</q><q cite=\"mailto://www.google.com\">MAILTO</q><q cite=\"tel://www.google.com\">TEL</q><q cite=\"ftp://www.google.com\">FTP</q><q>DATA</q><q>LDAP</q><q>ACROBAT</q><q>VBSCRIPT</q><q>FILE</q><q>RLOGIN</q><q>WEBCAL</q><q>JAVASCRIPT</q><q>MMS</q>');
750
750
  });
751
+ it('Should encode &, <, > and "', function() {
752
+ assert.equal(sanitizeHtml('"< & >"'), '&quot;&lt; &amp; &gt;&quot;');
753
+ });
754
+ it('Should not double encode ampersands on HTML entities', function() {
755
+ var textIn = 'This &amp; & that &reg; &#x0000A; &#10; &plusmn; OK?';
756
+ var expectedResult = 'This &amp; &amp; that &reg; &#x0000A; &#10; &plusmn; OK?';
757
+ var sanitizeHtmlOptions = {
758
+ parser: {
759
+ decodeEntities: false
760
+ }
761
+ };
762
+ assert.equal(sanitizeHtml(textIn, sanitizeHtmlOptions), expectedResult);
763
+ });
751
764
  });