Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sanitize-html

Package Overview
Dependencies
Maintainers
10
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sanitize-html - npm Package Compare versions

Comparing version 1.1.3 to 1.1.4

17

index.js

@@ -46,2 +46,3 @@ var htmlparser = require('htmlparser2');

var depth = 0;
var stack = [];
var skipMap = {};

@@ -52,2 +53,9 @@ var transformMap = {};

onopentag: function(name, attribs) {
stack.push({
tag: name,
attribs: attribs,
text: '',
tagPosition: result.length
});
var skip = false;

@@ -104,2 +112,6 @@ if (_.has(transformTagsMap, name)) {

}
if (depth) {
var frame = stack[depth - 1];
frame.text += text;
}
// It is NOT actually raw text, entities are already escaped.

@@ -110,2 +122,3 @@ // If we call escapeHtml here we wind up double-escaping.

onclosetag: function(name) {
var frame = stack.pop();
skipText = false;

@@ -125,2 +138,6 @@ depth--;

}
if (options.exclusiveFilter && options.exclusiveFilter(frame)) {
result = result.substr(0, frame.tagPosition);
return;
}
result += "</" + name + ">";

@@ -127,0 +144,0 @@ }

2

package.json
{
"name": "sanitize-html",
"version": "1.1.3",
"version": "1.1.4",
"description": "Clean up user-submitted HTML, preserving whitelisted elements and whitelisted attributes on a per-element basis",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -113,3 +113,21 @@ # sanitize-html

### Filters
You can provide a filter function to remove unwanted tags. Let's suppose we need to remove empty `a` tags like
```html
<a href="page/html"></a>
```
```javascript
sanitizeHtml(
'<p>This is <a href="http://www.linux.org"></a><br/>Linux</p>',
{
exclusiveFilter: function(frame) {
return frame.tag === 'a' && !frame.text.trim();
}
}
);
```
## Changelog
1.1.4: custom exclusion filter.

@@ -116,0 +134,0 @@ 1.1.3: moved to lodash. 1.1.2 pointed to the wrong version of lodash.

@@ -86,3 +86,14 @@ var assert = require("assert");

});
it('should skip empty a', function() {
assert.equal(
sanitizeHtml('<p>This is <a href="http://www.linux.org"></a><br/>Linux</p>',
{
exclusiveFilter : function(frame) {
return frame.tag === 'a' && !frame.text.trim();
}
}),
'<p>This is <br />Linux</p>'
);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc