require 'cgi' def strip_html(text) attribute_key = /[\w:_-]+/ attribute_value = /(?:[A-Za-z0-9]+|(?:'[^']*?'|"[^"]*?"))/ attribute = /(?:#{attribute_key}(?:\s*=\s*#{attribute_value})?)/ attributes = /(?:#{attribute}(?:\s+#{attribute})*)/ tag_key = attribute_key tag = %r{<[!/?\[]?(?:#{tag_key}|--)(?:\s+#{attributes})?\s*(?:[!/?\]]+|--)?>} text.gsub(tag, '').gsub(/\s+/, ' ').strip end module RFC822 EmailAddress = begin qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]' dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]' atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-' + '\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+' quoted_pair = '\\x5c[\\x00-\\x7f]' domain_literal = "\\x5b(?:#{dtext}|#{quoted_pair})*\\x5d" quoted_string = "\\x22(?:#{qtext}|#{quoted_pair})*\\x22" domain_ref = atom sub_domain = "(?:#{domain_ref}|#{domain_literal})" word = "(?:#{atom}|#{quoted_string})" domain = "#{sub_domain}(?:\\x2e#{sub_domain})*" local_part = "#{word}(?:\\x2e#{word})*" addr_spec = "#{local_part}\\x40#{domain}" pattern = /\A#{addr_spec}\z/ end end INTMATCH = /\A\d+\z/ def parseparam(vpstr, vdefault, vtype, vpositivelist = nil, vmatchregexpr = nil, vmin = 0, vmax = 999999) # nil strings are treated as empty strings vpstr = "" if vpstr.nil? && vtype == "str" if !vpstr.nil? then begin result = case vtype when "bool" then if ["true", true, "1", 1].include?(vpstr) then true else false end when "int", "id" then if (vpstr == "") || ( vpstr.class == String && (INTMATCH =~ vpstr).nil? ) then result = vdefault else if vpositivelist.nil? || vpositivelist.include?(vpstr.to_i) then result = vpstr.to_i else result = vdefault end end if vtype == "id" then result.to_s else result end when "str" then if (vmax >= vmin) && ( (vpstr.length < vmin) || (vpstr.length > vmax) ) then result = vdefault else if vpositivelist then if vpositivelist.include?(vpstr) then result = vpstr.to_s else result = vdefault end else result = vpstr.to_s end if vmatchregexpr then if (vmatchregexpr =~ result).nil? then result = vdefault else result = vpstr.to_s end end end result when "date" then if vpstr.year == "" then vdefault else vpstr end when "htmlescape" then CGI::escapeHTML(vpstr.to_s) when "email" then if (RFC822::EmailAddress =~ vpstr).nil? then vdefault else vpstr.to_s end end rescue result = vdefault end return result else return vdefault end end