Skip to content

Commit d0b658b

Browse files
authored
Moves the main file to project root and removes build (#380)
* Moves the main file to project root and removes build * Replaces test reference to dist file * Removes dist dir
1 parent e26ad95 commit d0b658b

File tree

6 files changed

+38
-51
lines changed

6 files changed

+38
-51
lines changed

.eslintignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
node_modules
2-
dist

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ package-lock.json
22
npm-debug.log
33
*.DS_Store
44
node_modules
5-
dist
65
# We do not commit CSS, only LESS
76
public/css/*.css

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Changelog
22

33
2.0.0-beta:
4+
- Moves the `index.js` file to the project root and removes all build steps within the package. Going forward, it is up to the developer to include sanitize-html in their project builds as-needed. This removes major points of conflict with project code and frees this module to not worry about myriad build-related questions.
45
- Replaces lodash with utility packages: klona, is-plain-object, deepmerge, escape-string-regexp.
56

67
1.27.1 (2020-07-15):

src/index.js renamed to index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ function sanitizeHtml(html, options, _recursing) {
164164
var transFun;
165165
if (typeof transform === 'function') {
166166
transFun = transform;
167-
} else if (typeof transform === "string") {
167+
} else if (typeof transform === 'string') {
168168
transFun = sanitizeHtml.simpleTransform(transform);
169169
}
170170
if (tag === '*') {
@@ -306,7 +306,7 @@ function sanitizeHtml(html, options, _recursing) {
306306
if (isRelativeUrl) {
307307
// default value of allowIframeRelativeUrls is true
308308
// unless allowedIframeHostnames or allowedIframeDomains specified
309-
allowed = has(options, "allowIframeRelativeUrls")
309+
allowed = has(options, 'allowIframeRelativeUrls')
310310
? options.allowIframeRelativeUrls
311311
: (!options.allowedIframeHostnames && !options.allowedIframeDomains);
312312
} else if (options.allowedIframeHostnames || options.allowedIframeDomains) {
@@ -362,7 +362,7 @@ function sanitizeHtml(html, options, _recursing) {
362362
}
363363
if (a === 'style') {
364364
try {
365-
var abstractSyntaxTree = postcss.parse(name + " {" + value + "}");
365+
var abstractSyntaxTree = postcss.parse(name + ' {' + value + '}');
366366
var filteredAST = filterCss(abstractSyntaxTree, options.allowedStyles);
367367

368368
value = stringifyStyleAttributes(filteredAST);
@@ -386,9 +386,9 @@ function sanitizeHtml(html, options, _recursing) {
386386
});
387387
}
388388
if (options.selfClosing.indexOf(name) !== -1) {
389-
result += " />";
389+
result += ' />';
390390
} else {
391-
result += ">";
391+
result += '>';
392392
if (frame.innerText && !hasText && !options.textFilter) {
393393
result += frame.innerText;
394394
}
@@ -481,7 +481,7 @@ function sanitizeHtml(html, options, _recursing) {
481481
return;
482482
}
483483

484-
result += "</" + name + ">";
484+
result += '</' + name + '>';
485485
if (skip) {
486486
result = tempResult + escapeHtml(result);
487487
tempResult = '';

package.json

+4-16
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@
33
"version": "1.27.1",
44
"description": "Clean up user-submitted HTML, preserving whitelisted elements and whitelisted attributes on a per-element basis",
55
"sideEffects": false,
6-
"main": "dist/sanitize-html.js",
7-
"files": [
8-
"dist/"
9-
],
6+
"main": "index.js",
107
"scripts": {
11-
"build": "mkdir -p dist && browserify src/index.js > dist/sanitize-html-es2015.js --standalone 'sanitizeHtml' && babel dist/sanitize-html-es2015.js --out-file dist/sanitize-html.js --presets=@babel/preset-env",
12-
"minify": "npm run build && uglifyjs dist/sanitize-html.js > dist/sanitize-html.min.js",
13-
"prepublishOnly": "npm run minify",
14-
"test": "npx eslint . && npm run prepublishOnly && mocha test/test.js"
8+
"test": "npx eslint . && mocha test/test.js"
159
},
1610
"repository": {
1711
"type": "git",
@@ -35,11 +29,6 @@
3529
"srcset": "^2.0.1"
3630
},
3731
"devDependencies": {
38-
"@babel/cli": "^7.8.4",
39-
"@babel/core": "^7.8.4",
40-
"@babel/preset-env": "^7.8.4",
41-
"babelify": "^10.0.0",
42-
"browserify": "^16.2.3",
4332
"eslint": "^4.0.0",
4433
"eslint-config-apostrophe": "^3.1.0",
4534
"eslint-config-standard": "^11.0.0",
@@ -48,7 +37,6 @@
4837
"eslint-plugin-promise": "^3.8.0",
4938
"eslint-plugin-standard": "^3.1.0",
5039
"mocha": "^5.2.0",
51-
"sinon": "^9.0.2",
52-
"uglify-js": "^3.8.0"
40+
"sinon": "^9.0.2"
5341
}
54-
}
42+
}

test/test.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint-disable no-useless-escape */
2-
var assert = require("assert");
2+
var assert = require('assert');
33
const sinon = require('sinon');
44

55
describe('sanitizeHtml', function() {
66
var sanitizeHtml;
77
it('should be successfully initialized', function() {
8-
sanitizeHtml = require('../dist/sanitize-html.js');
8+
sanitizeHtml = require('../index.js');
99
});
1010
it('should escape self closing tags', () => {
1111
assert.equal(sanitizeHtml('before <img src="test.png" /> after', {
@@ -241,7 +241,7 @@ describe('sanitizeHtml', function() {
241241
);
242242
});
243243

244-
it("Should expose a node's inner text and inner HTML to the filter", function() {
244+
it('Should expose a node\'s inner text and inner HTML to the filter', function() {
245245
assert.strictEqual(
246246
sanitizeHtml('<p>12<a href="http://www.linux.org"><br/>3<br></a><span>4</span></p>', {
247247
exclusiveFilter: function(frame) {
@@ -390,7 +390,7 @@ describe('sanitizeHtml', function() {
390390
it('should not crash on bad markup', function() {
391391
assert.equal(
392392
sanitizeHtml(
393-
"<p a"
393+
'<p a'
394394
),
395395
''
396396
);
@@ -415,7 +415,7 @@ describe('sanitizeHtml', function() {
415415

416416
it('should deliver a warning if using vulnerable tags', function() {
417417
const spy = sinon.spy(console, 'warn');
418-
const message = `\n\n⚠️ Your \`allowedTags\` option includes, \`style\`, which is inherently\nvulnerable to XSS attacks. Please remove it from \`allowedTags\`.\nOr, to disable this warning, add the \`allowVulnerableTags\` option\nand ensure you are accounting for this risk.\n\n`;
418+
const message = '\n\n⚠️ Your `allowedTags` option includes, `style`, which is inherently\nvulnerable to XSS attacks. Please remove it from `allowedTags`.\nOr, to disable this warning, add the `allowVulnerableTags` option\nand ensure you are accounting for this risk.\n\n';
419419

420420
sanitizeHtml(
421421
'<style></style>',
@@ -618,27 +618,27 @@ describe('sanitizeHtml', function() {
618618
});
619619
it('should respect htmlparser2 options when passed in', function() {
620620
assert.equal(
621-
sanitizeHtml("<Archer><Sterling>I am</Sterling></Archer>", {
621+
sanitizeHtml('<Archer><Sterling>I am</Sterling></Archer>', {
622622
allowedTags: false,
623623
allowedAttributes: false
624624
}),
625-
"<archer><sterling>I am</sterling></archer>"
625+
'<archer><sterling>I am</sterling></archer>'
626626
);
627627
assert.equal(
628-
sanitizeHtml("<Archer><Sterling>I am</Sterling></Archer>", {
628+
sanitizeHtml('<Archer><Sterling>I am</Sterling></Archer>', {
629629
allowedTags: false,
630630
allowedAttributes: false,
631631
parser: {
632632
lowerCaseTags: false
633633
}
634634
}),
635-
"<Archer><Sterling>I am</Sterling></Archer>"
635+
'<Archer><Sterling>I am</Sterling></Archer>'
636636
);
637637
});
638638
it('should not crash due to tag names that are properties of the universal Object prototype', function() {
639639
assert.equal(
640-
sanitizeHtml("!<__proto__>!"),
641-
"!!");
640+
sanitizeHtml('!<__proto__>!'),
641+
'!!');
642642
});
643643
it('should correctly maintain escaping when allowing a nonTextTags tag other than script or style', function() {
644644
assert.equal(
@@ -719,10 +719,10 @@ describe('sanitizeHtml', function() {
719719
sanitizeHtml(sanitizeString, {
720720
allowedTags: false,
721721
allowedAttributes: {
722-
'*': ["dir"],
723-
p: ["dir", "style"],
724-
li: ["style"],
725-
span: ["style"]
722+
'*': ['dir'],
723+
p: ['dir', 'style'],
724+
li: ['style'],
725+
span: ['style']
726726
},
727727
allowedStyles: {
728728
'*': {
@@ -737,44 +737,44 @@ describe('sanitizeHtml', function() {
737737
});
738738
it('Should remove empty style tags', function() {
739739
assert.equal(
740-
sanitizeHtml("<span style=''></span>", {
740+
sanitizeHtml('<span style=\'\'></span>', {
741741
allowedTags: false,
742742
allowedAttributes: false
743743
}),
744-
"<span></span>"
744+
'<span></span>'
745745
);
746746
});
747747
it('Should remote invalid styles', function() {
748748
assert.equal(
749-
sanitizeHtml("<span style='color: blue; text-align: justify'></span>", {
749+
sanitizeHtml('<span style=\'color: blue; text-align: justify\'></span>', {
750750
allowedTags: false,
751751
allowedAttributes: {
752-
"span": ["style"]
752+
'span': ['style']
753753
},
754754
allowedStyles: {
755755
'span': {
756-
"color": [/blue/],
757-
"text-align": [/left/]
756+
'color': [/blue/],
757+
'text-align': [/left/]
758758
}
759759
}
760760
}), '<span style="color:blue"></span>'
761761
);
762762
});
763763
it('Should allow a specific style from global', function() {
764764
assert.equal(
765-
sanitizeHtml("<span style='color: yellow; text-align: center; font-family: helvetica'></span>", {
765+
sanitizeHtml('<span style=\'color: yellow; text-align: center; font-family: helvetica\'></span>', {
766766
allowedTags: false,
767767
allowedAttributes: {
768-
"span": ["style"]
768+
'span': ['style']
769769
},
770770
allowedStyles: {
771771
'*': {
772-
"color": [/yellow/],
773-
"text-align": [/center/]
772+
'color': [/yellow/],
773+
'text-align': [/center/]
774774
},
775775
'span': {
776-
"color": [/green/],
777-
"font-family": [/helvetica/]
776+
'color': [/green/],
777+
'font-family': [/helvetica/]
778778
}
779779
}
780780
}), '<span style="color:yellow;text-align:center;font-family:helvetica"></span>'

0 commit comments

Comments
 (0)