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/README.md +4 -0
- package/dist/index.js +2 -1
- package/dist/sanitize-html.js +6695 -6745
- package/dist/sanitize-html.min.js +12 -13
- package/package.json +1 -1
- package/src/index.js +4 -1
- package/test/test.js +13 -0
package/package.json
CHANGED
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(
|
|
414
|
+
return s.replace(/&(?![a-zA-Z0-9#]{1,7};)/g, '&') // Match ampersands not part of existing HTML entity
|
|
415
|
+
.replace(/</g, '<')
|
|
416
|
+
.replace(/\>/g, '>')
|
|
417
|
+
.replace(/\"/g, '"');
|
|
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('"< & >"'), '"< & >"');
|
|
753
|
+
});
|
|
754
|
+
it('Should not double encode ampersands on HTML entities', function() {
|
|
755
|
+
var textIn = 'This & & that ® 
 ± OK?';
|
|
756
|
+
var expectedResult = 'This & & that ® 
 ± OK?';
|
|
757
|
+
var sanitizeHtmlOptions = {
|
|
758
|
+
parser: {
|
|
759
|
+
decodeEntities: false
|
|
760
|
+
}
|
|
761
|
+
};
|
|
762
|
+
assert.equal(sanitizeHtml(textIn, sanitizeHtmlOptions), expectedResult);
|
|
763
|
+
});
|
|
751
764
|
});
|