Changeset 5446

Show
Ignore:
Timestamp:
02/03/08 12:12:34 (3 years ago)
Author:
uta
Message:

rails_protection

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/rails_protection/trunk/rails_protection/lib/custom_sanitizer.rb

    r4336 r5446  
    3535        }.merge(options) 
    3636        tag_stack = [] 
     37        ignore_tag_stack = [] 
    3738        result = '' 
    3839        if options[:rule].is_a?(Hash) 
     
    5354          # html tag(close) 
    5455          if match_data[2] 
    55             if match_data[2] =~ %r(</([a-zA-Z0-9]+)>) 
     56            if match_data[2] =~ %r(</([a-zA-Z0-9:!]+)>) 
    5657              match_tag = $1.downcase 
    5758              if match_tag == tag_stack.last 
    5859                tag_stack.pop 
    5960                result << "</#{match_tag}>" 
     61                next 
     62              end 
     63              if ignore_tag_stack.include?(match_tag) 
    6064                next 
    6165              end 
     
    6872          if match_data[3] 
    6973            attr = {} 
    70             if match_data[3] =~ %r(<([a-zA-Z0-9]+)(.*)>)mn 
     74            if match_data[3] =~ %r(<([a-zA-Z0-9:!]+)(.*)>)mn 
    7175              match_tag     = $1.downcase 
    7276              sym_tag       = match_tag.to_sym 
     
    97101                  end 
    98102                end 
    99                 result << "<#{match_tag}" 
    100                 attr.each do |key, value| 
    101                   value.sub!(Regexp.new("^(#{options[:class_prefix]})?"), options[:class_prefix]) if key == :class 
    102                   result << %Q( #{key.to_s}="#{value}") 
    103                 end 
    104                 if rule[sym_tag][:empty_tag] 
    105                   result << '/>' 
     103                if rule[sym_tag][:ignore] 
     104                  ignore_tag_stack << match_tag 
    106105                else 
    107                   result << '>' 
    108                   tag_stack << match_tag 
     106                  result << "<#{match_tag}" 
     107                  attr.each do |key, value| 
     108                    value.sub!(Regexp.new("^(#{options[:class_prefix]})?"), options[:class_prefix]) if key == :class 
     109                    result << %Q( #{key.to_s}="#{value}") 
     110                  end 
     111                  if rule[sym_tag][:empty_tag] 
     112                    result << '/>' 
     113                  else 
     114                    result << '>' 
     115                    tag_stack << match_tag 
     116                  end 
    109117                end 
    110118                next