filterhtml
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -267,4 +267,5 @@ var FilterHTML = (function() { | ||
text_chars += this.escape_data(this.curr_char); | ||
this.state = 'script-data'; | ||
} | ||
this.state = 'script-data'; | ||
} else { | ||
@@ -302,2 +303,16 @@ this.filtered_html += filtered_text; | ||
HTMLFilter.prototype.get_tag_spec = function(tag_name) { | ||
var tag_spec = this.spec[tag_name]; | ||
if (typeof(tag_spec) === 'function') { | ||
tag_spec = tag_spec(tag_name, this.tag_stack); | ||
} | ||
if (!tag_spec) { | ||
tag_spec = null; | ||
} | ||
return tag_spec; | ||
}; | ||
HTMLFilter.prototype.escape_data = function(data_char) { | ||
@@ -431,3 +446,3 @@ if (HTML_ESCAPE_CHARS[data_char]) { | ||
HTMLFilter.prototype.filter_opening_tag = function() { | ||
var tag_output, i, is_void, tag_name, tag_parts, attributes, attribute; | ||
var tag_output, i, is_void, tag_name, tag_spec, tag_parts, attributes, attribute, is_recognised_tag; | ||
@@ -439,5 +454,9 @@ tag_output = ''; | ||
tag_name = this.extract_tag_name(); | ||
tag_spec = this.get_tag_spec(tag_name); | ||
if (tag_name === 'script') { | ||
this.state = 'script-data'; | ||
} else if (tag_spec === false) { | ||
this.tag_removing = tag_name; | ||
this.state = 'skip-data'; | ||
} else { | ||
@@ -457,3 +476,5 @@ for (i = 0; i !== this.removals.length; ++i) { | ||
if (this.spec[tag_name]) { | ||
is_recognised_tag = tag_spec !== null && tag_spec !== false; | ||
if (is_recognised_tag) { | ||
while (this.curr_char !== '>' && this.curr_char !== '') { | ||
@@ -493,3 +514,3 @@ this.extract_whitespace(); | ||
HTMLFilter.prototype.filter_closing_tag = function() { | ||
var tag_output, i, is_void, tag_name, tag_parts, opening_tag_name; | ||
var tag_output, i, is_void, tag_name, tag_spec, tag_parts, opening_tag_name, is_recognised_tag; | ||
@@ -519,4 +540,7 @@ tag_output = ''; | ||
tag_name = tag_parts[0]; | ||
tag_spec = this.get_tag_spec(tag_name); | ||
if (this.spec[tag_name] && !is_void) { | ||
is_recognised_tag = tag_spec !== null && tag_spec !== false; | ||
if (is_recognised_tag && !is_void) { | ||
this.extract_whitespace(); | ||
@@ -549,5 +573,5 @@ if (this.curr_char === '>') { | ||
HTMLFilter.prototype.filter_attribute = function(tag_name) { | ||
var tag_spec, attribute_name, whitespace, is_allowed, value; | ||
var tag_spec, attribute_name, whitespace, is_allowed, value, tag_spec; | ||
tag_spec = this.spec[tag_name]; | ||
tag_spec = this.get_tag_spec(tag_name); | ||
@@ -584,3 +608,3 @@ attribute_name = this.extract_attribute_name(); | ||
HTMLFilter.prototype.filter_value = function(tag_name, attribute_name) { | ||
var value, quote, rules, global_rules, new_value; | ||
var value, quote, rules, global_rules, new_value, tag_spec; | ||
@@ -607,3 +631,8 @@ value = ''; | ||
rules = this.spec[tag_name][attribute_name]; | ||
rules = null; | ||
tag_spec = this.get_tag_spec(tag_name); | ||
if (tag_spec !== null) { | ||
rules = tag_spec[attribute_name]; | ||
} | ||
global_rules = null; | ||
@@ -610,0 +639,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "FilterHTML: A whitelisting HTML filter for Python and JavaScript", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "url": "https://github.com/dcollien/FilterHTML" |
Sorry, the diff of this file is not supported yet
45960
1041