diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-02-05 10:27:34 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-02-05 10:27:34 +0000 |
commit | 9b64dfe3b8f0343ebf97ae80d3a4ec3f4bd115b3 (patch) | |
tree | 7acd7b77321fdbc63149b47fde3bace6f7733614 /lib/cgi-lib.rb | |
parent | 06d4e3b42d836b762c29cdc9dc7181caf14dcdec (diff) |
990205
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/cgi-lib.rb')
-rw-r--r-- | lib/cgi-lib.rb | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/lib/cgi-lib.rb b/lib/cgi-lib.rb index ef717b20bf..2089a9c9a5 100644 --- a/lib/cgi-lib.rb +++ b/lib/cgi-lib.rb @@ -25,6 +25,20 @@ # # print CGI.header("HTTP/1.0 200 OK", "Content-Type: text/html") # print CGI.header # == print CGI.header("Content-Type: text/html") +# +# make HTML tag string +# CGI.tag("element", {"attribute_name"=>"attribute_value"}){"content"} +# +# print CGI.tag("HTML"){ +# CGI.tag("HEAD"){ CGI.tag("TITLE"){"TITLE"} } + +# CGI.tag("BODY"){ +# CGI.tag("FORM", {"ACTION"=>"test.rb", "METHOD"=>"POST"}){ +# CGI.tag("INPUT", {"TYPE"=>"submit", "VALUE"=>"submit"}) +# } + +# CGI.tag("HR") +# } +# } + # if running on Windows(IIS or PWS) then change cwd. if ENV['SERVER_SOFTWARE'] =~ /^Microsoft-/ then @@ -67,7 +81,13 @@ class CGI < SimpleDelegator str.gsub!(/%([0-9a-fA-F]{2})/){ [$1.hex].pack("c") } str end - module_function :escape, :unescape + + # escape HTML + def escapeHTML(str) + str.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<") + end + + module_function :escape, :unescape, :escapeHTML def initialize(input = $stdin) @@ -97,12 +117,12 @@ class CGI < SimpleDelegator if ENV.has_key?('HTTP_COOKIE') @cookie = {} ENV['HTTP_COOKIE'].split("; ").each do |x| - key, val = x.split(/=/,2).collect{|x|unescape(x)} - if @cookie.include?(key) - @cookie[key] += "\0" + (val or "") - else - @cookie[key] = (val or "") - end + key, val = x.split(/=/,2).collect{|x|unescape(x)} + if @cookie.include?(key) + @cookie[key] += "\0" + (val or "") + else + @cookie[key] = (val or "") + end end end end @@ -123,6 +143,13 @@ class CGI < SimpleDelegator (options['secure'] ? '; secure' : '') end + def CGI.tag(element, attributes = {}) + "<" + escapeHTML(element) + attributes.collect{|name, value| + " " + escapeHTML(name) + '="' + escapeHTML(value) + '"' + }.to_s + ">" + + (iterator? ? yield.to_s + "</" + escapeHTML(element) + ">" : "") + end + def CGI.message(msg, title = "", header = ["Content-Type: text/html"]) print CGI.header(*header) print "<html><head><title>" |