From 61aa76f876894d06e37bf798fef6ab2334319c98 Mon Sep 17 00:00:00 2001 From: Nera Liu Date: Wed, 24 Jun 2015 13:18:13 +0800 Subject: [PATCH] minor enhancement of the code and increase code coverage to 100% --- src/html-purify.js | 13 +++++-------- src/tag-attr-list.js | 33 ++++++++++++++++----------------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/html-purify.js b/src/html-purify.js index a5bacd1..5fff1dd 100755 --- a/src/html-purify.js +++ b/src/html-purify.js @@ -29,6 +29,7 @@ var CssParser = require('css-js'); this.cssParser = new CssParser({"ver": "strict", "throwError": false}); } + // TODO: introduce polyfill for Array.indexOf function contains(arr, element) { for (var i = 0, len = arr.length; i < len; i++) { if (arr[i] === element) { @@ -55,14 +56,11 @@ var CssParser = require('css-js'); case 1: this.output += ch; break; + case 2: - if (prevState === 35) { - this.attrVals[attributeName] = attributeValue; - } - if (prevState === 36) { - this.attrVals[attributeName] = attributeValue; - } - if (prevState === 40) { + if (prevState === 35 || + prevState === 36 || + prevState === 40) { this.attrVals[attributeName] = attributeValue; } @@ -121,7 +119,6 @@ var CssParser = require('css-js'); } } - Purifier.prototype.purify = function (data) { this.output = ''; this.attrVals = {}; diff --git a/src/tag-attr-list.js b/src/tag-attr-list.js index 442c8ca..c137554 100644 --- a/src/tag-attr-list.js +++ b/src/tag-attr-list.js @@ -121,7 +121,6 @@ Whitelist.Tags = [ "wbr" ]; - Whitelist.Attributes = [ "ept", "acceptCharset", @@ -222,22 +221,22 @@ Whitelist.Attributes = [ ]; Whitelist.HrefAttributes = [ -"action", -"background", -"codebase", -"cite", -"classid", -"formaction", -"folder", -"href", -"icon", -"longdesc", -"manifest", -"profile", -"poster", -"src", -"usemap", -"xlink:href" + "action", + "background", + "codebase", + "cite", + "classid", + "formaction", + "folder", + "href", + "icon", + "longdesc", + "manifest", + "profile", + "poster", + "src", + "usemap", + "xlink:href" ]; module.exports = Whitelist;