Socket
Socket
Sign inDemoInstall

clean-html

Package Overview
Dependencies
12
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.3 to 1.5.0

14

index.js

@@ -175,9 +175,17 @@ var htmlparser = require('htmlparser2'),

if (options['remove-empty-tags'].indexOf(node.name) != -1) {
if (isListedInOptions('remove-empty-tags', node.name)) {
return isEmpty(node);
}
return options['remove-tags'].indexOf(node.name) != -1;
return isListedInOptions('remove-tags', node.name);
}
function isListedInOptions(optionsArrayName, name) {
var matches = options[optionsArrayName].filter(function(option) {
return option instanceof RegExp && option.test(name) || option === name;
});
return !!matches.length;
}
function renderText(node) {

@@ -235,3 +243,3 @@ if (shouldRemove(node)) {

for (var attrib in node.attribs) {
if (options['remove-attributes'].indexOf(attrib) == -1) {
if (!isListedInOptions('remove-attributes', attrib)) {
openTag += ' ' + attrib + '="' + removeExtraSpace(node.attribs[attrib]) + '"';

@@ -238,0 +246,0 @@ }

{
"name": "clean-html",
"version": "1.4.3",
"version": "1.5.0",
"description": "HTML cleaner and beautifier",

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

@@ -120,3 +120,3 @@ ## HTML cleaner and beautifier

Type: Array
Type: Mixed Array (strings or RegExp pattern)
Default: `['align', 'bgcolor', 'border', 'cellpadding', 'cellspacing', 'color', 'height', 'target', 'valign', 'width']`

@@ -135,3 +135,3 @@

Type: Array
Type: Mixed Array (strings or RegExp pattern)
Default: `[]`

@@ -143,3 +143,3 @@

Type: Array
Type: Mixed Array (strings or RegExp pattern)
Default: `['center', 'font']`

@@ -146,0 +146,0 @@

@@ -0,1 +1,7 @@

1.5.0
-----
Regular expressions are now supported in the remove-attributes,
remove-empty-tags and remove-tags options.
1.4.3

@@ -2,0 +8,0 @@ -----

@@ -61,2 +61,6 @@ var assert = require('assert'),

});
// test that attribute is removed when it matches at least one pattern included in remove-attributes
cleaner.clean('<span _test-color="red">foo</span>', {'remove-attributes': [/_test-[a-z0-9-]+/i]}, function (html) {
assert.equal(html, '<span>foo</span>');
});

@@ -80,2 +84,6 @@ // test that comment is not removed when remove-comments is false

});
// test that empty tag is removed when it matches at least one pattern included in remove-empty-tags
cleaner.clean('<app-pam-pam-pam></app-pam-pam-pam>', {'remove-empty-tags': [/^app-.*/i]}, function (html) {
assert.equal(html, '');
});

@@ -90,2 +98,6 @@ // test that tag is not removed when not included in remove-tags

});
// test that tag is removed and child is preserved when it matches at least one pattern included in remove-tags
cleaner.clean('<app-test>foo</app-test>', {'remove-tags': [/app-.+/]}, function (html) {
assert.equal(html, 'foo');
});

@@ -92,0 +104,0 @@ // test that unsupported tags are removed

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc