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

html-janitor

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-janitor - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

6

CHANGELOG.md

@@ -5,4 +5,10 @@ # HTML Janitor

## 0.3.2
Adds IE NodeWalker compatibility change from [daniel-nelson](https://github.com/daniel-nelson), thanks.
*Note*: there are no CI tests for IE so support is not guaranteed
## 0.3.1
No functionality changes but corrects the package json for the NPM release

2

package.json
{
"name": "html-janitor",
"version": "0.3.1",
"version": "0.3.2",
"main": "src/html-janitor.js",

@@ -5,0 +5,0 @@ "scripts": {

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

html-janitor
============
# html-janitor
Sanitises HTML.
![](https://circleci.com/gh/guardian/html-janitor.png?circle-token=bd24300ee650966837a73bfe03386828f0192c06)
Uses UMD for support in AMD and Common JS environments.

@@ -7,0 +8,0 @@

@@ -11,2 +11,6 @@ (function (root, factory) {

/**
* @param {Object} config.tags Dictionary of allowed tags.
* @param {boolean} config.keepNestedBlockElements Default false.
*/
function HTMLJanitor(config) {

@@ -80,4 +84,2 @@ this.config = config;

var isNotTopContainer = !! parentNode.parentNode;
// TODO: Don't hardcore this — this is not invalid markup. Should be
// configurable.
var isNestedBlockElement =

@@ -90,3 +92,3 @@ isBlockElement(parentNode) &&

// is invalid.
if (!this.config.tags[nodeName] || isInvalid || isNestedBlockElement) {
if (!this.config.tags[nodeName] || isInvalid || (!this.config.keepNestedBlockElements && isNestedBlockElement)) {
// Do not keep the inner text of SCRIPT/STYLE elements.

@@ -130,3 +132,4 @@ if (! (node.nodeName === 'SCRIPT' || node.nodeName === 'STYLE')) {

return document.createTreeWalker(node,
NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT);
NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT,
null, false);
}

@@ -133,0 +136,0 @@

@@ -10,3 +10,4 @@ define([ 'html-janitor' ], function (HTMLJanitor) {

ul: {},
li: {}
li: {},
div: {}
}

@@ -36,6 +37,6 @@

it('should remove elements not in the whitelist', function () {
var div = document.createElement('div');
var aside = document.createElement('aside');
var p = document.createElement('p');
div.appendChild(p);
expect(janitor.clean(div.outerHTML)).toBe('<p></p>');
aside.appendChild(p);
expect(janitor.clean(aside.outerHTML)).toBe('<p></p>');
});

@@ -88,4 +89,35 @@

});
it('should remove nested span elements', function() {
var html ='<p><span>Hello <span>world</span></span></p>';
expect(janitor.clean(html)).toBe('<p>Hello world</p>');
});
it('should not allow nested block elements by default', function() {
var html = '<div>Hello <div>world</div></div>';
expect(janitor.clean(html)).toBe('<div>Hello world</div>');
});
});
describe('janitor that allows nested block elements', function () {
var janitor;
var config = {
tags: {
div: {}
},
keepNestedBlockElements: true
};
beforeEach(function () {
janitor = new HTMLJanitor(config);
});
it('should allow nested block elements', function() {
var html = '<div>Hello <div>world</div></div>';
expect(janitor.clean(html)).toBe('<div>Hello <div>world</div></div>');
});
});
});
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