Skip to content
This repository was archived by the owner on Jul 15, 2019. It is now read-only.

Commit 61aa76f

Browse files
committed
minor enhancement of the code and increase code coverage to 100%
1 parent 02b2cee commit 61aa76f

2 files changed

Lines changed: 21 additions & 25 deletions

File tree

src/html-purify.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var CssParser = require('css-js');
2929
this.cssParser = new CssParser({"ver": "strict", "throwError": false});
3030
}
3131

32+
// TODO: introduce polyfill for Array.indexOf
3233
function contains(arr, element) {
3334
for (var i = 0, len = arr.length; i < len; i++) {
3435
if (arr[i] === element) {
@@ -55,14 +56,11 @@ var CssParser = require('css-js');
5556
case 1:
5657
this.output += ch;
5758
break;
59+
5860
case 2:
59-
if (prevState === 35) {
60-
this.attrVals[attributeName] = attributeValue;
61-
}
62-
if (prevState === 36) {
63-
this.attrVals[attributeName] = attributeValue;
64-
}
65-
if (prevState === 40) {
61+
if (prevState === 35 ||
62+
prevState === 36 ||
63+
prevState === 40) {
6664
this.attrVals[attributeName] = attributeValue;
6765
}
6866

@@ -121,7 +119,6 @@ var CssParser = require('css-js');
121119
}
122120
}
123121

124-
125122
Purifier.prototype.purify = function (data) {
126123
this.output = '';
127124
this.attrVals = {};

src/tag-attr-list.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ Whitelist.Tags = [
121121
"wbr"
122122
];
123123

124-
125124
Whitelist.Attributes = [
126125
"ept",
127126
"acceptCharset",
@@ -222,22 +221,22 @@ Whitelist.Attributes = [
222221
];
223222

224223
Whitelist.HrefAttributes = [
225-
"action",
226-
"background",
227-
"codebase",
228-
"cite",
229-
"classid",
230-
"formaction",
231-
"folder",
232-
"href",
233-
"icon",
234-
"longdesc",
235-
"manifest",
236-
"profile",
237-
"poster",
238-
"src",
239-
"usemap",
240-
"xlink:href"
224+
"action",
225+
"background",
226+
"codebase",
227+
"cite",
228+
"classid",
229+
"formaction",
230+
"folder",
231+
"href",
232+
"icon",
233+
"longdesc",
234+
"manifest",
235+
"profile",
236+
"poster",
237+
"src",
238+
"usemap",
239+
"xlink:href"
241240
];
242241

243242
module.exports = Whitelist;

0 commit comments

Comments
 (0)