Class: CGI

Inherits:
Object
  • Object
show all
Defined in:
lib/sbsm/cgi.rb,
lib/cgi/drbsession.rb

Defined Under Namespace

Modules: TagMaker Classes: Session

Class Method Summary collapse

Class Method Details

.escapeHTML(string) ⇒ Object



92
93
94
95
# File 'lib/sbsm/cgi.rb', line 92

def CGI::escapeHTML(string)
   s = string.to_s.frozen? ? string.to_s : string.to_s.force_encoding('UTF-8')
  s.gsub(/&(?![^;]{2,6};)/, '&amp;').gsub(/\"/, '&quot;').gsub(/>/, '&gt;').gsub(/</, '&lt;')
end

.initialize_without_offline_prompt(*args) ⇒ Object

Lets satisfy cgi-offline prompt, even if request does not have REQUEST_METHOD. (It must be mostly for test purpose). See ruby-doc.org/stdlib-2.3.1/libdoc/cgi/rdoc/CGI.html#method-c-new



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sbsm/cgi.rb', line 33

def self.initialize_without_offline_prompt(*args)
  cgi_input = true
  unless ENV.has_key?('REQUEST_METHOD')
    cgi_input = false
    ENV['REQUEST_METHOD'] = 'GET'
  end
  cgi = CGI.new(*args)
  unless cgi_input
    ENV.delete('REQUEST_METHOD')
  end
  cgi
end

.pretty(string, shift = " ") ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/sbsm/cgi.rb', line 65

def CGI::pretty(string, shift = "  ")
  lines = string.gsub(/(?!\A)<(?!\/(pre|textarea))(?:.)*?>/ni, "\n\\0").gsub(/<(?!(pre|textarea))(?:.)*?>(?!\n)/i, "\\0\n")
 end_pos = 0
preformatted = []
while (end_pos = lines.index(/<\/pre\s*>/i, end_pos)) \
    && (start_pos = lines.rindex(/<pre(\s+[^>]+)?>/i, end_pos))
  start_pos += $~[0].length
  preformatted.push(lines[ start_pos ... end_pos ])
  lines[ start_pos ... end_pos ] = ''
  end_pos  = start_pos + 6
end
  end_pos = 0
  while end_pos = lines.index(/^<\/(\w+)/, end_pos)
    element = $1.dup
    start_pos = lines.rindex(/^\s*<#{element}/i, end_pos)
    lines[start_pos ... end_pos] = "__" + lines[start_pos ... end_pos].gsub(/\n(?!\z)/, "\n" + shift) + "__"
  end
  pretty = lines.gsub(/^((?:#{Regexp::quote(shift)})*)__(?=<\/?\w)/, '\1')
pos = 0
preformatted.each { |pre|
  if(pos = pretty.index(/<\/pre\s*>/i, pos))
    pretty[pos,0] = pre
    pos += pre.length + 6
  end
}
pretty
end