Skip to content

Commit

Permalink
Repaired bug in original white_list so anything after 'bad tag' was s…
Browse files Browse the repository at this point in the history
…tripped until next 'good tag' - now plugin is nest-aware and strip anything inside bad tag
  • Loading branch information
Bernard Potocki committed Mar 19, 2009
1 parent ce1ba3b commit 669c759
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/white_list_model.rb
Expand Up @@ -99,7 +99,7 @@ def white_list_parse(text, options = {})
bad_tags = Set.new(options[:bad_tags])
prot = Set.new(options[:protocols])
tags = Set.new(options[:tags])
block = lambda { |node, bad| bad_tags.include?(bad) ? nil : node.to_s.gsub(/</, '&lt;') }
@included_bad_tags = []
returning [] do |new_text|
tokenizer = HTML::Tokenizer.new(text)
bad = nil
Expand All @@ -116,19 +116,28 @@ def white_list_parse(text, options = {})
end
end if node.attributes
if tags.include?(node.name)
bad = nil
node
elsif bad_tags.include?(node.name)
indent_bad_tag(node)
else
bad = node.name
block.call node, bad
node.to_s.gsub(/</, '&lt;') if @included_bad_tags.empty?
end
else
block.call node, bad
node.to_s.gsub(/</, '&lt') if @included_bad_tags.empty?
end
end
end.join
end

def indent_bad_tag(tag)
case tag.closing
when nil then @included_bad_tags << tag.name
when :close then @included_bad_tags.delete_at( @included_bad_tags.index(tag.name) ) rescue nil
else nil
end
nil
end

def contains_bad_protocols?(value, protocols)
protocol_separator = /:|(&#0*58)|(&#x70)|(%|&#37;)3A/
value =~ protocol_separator && !protocols.include?(value.split(protocol_separator).first)
Expand Down

0 comments on commit 669c759

Please sign in to comment.