cgi 0.3.3-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of cgi might be problematic. Click here for more details.

checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4310af39d77c46fa21525427237ec1d2502a4f251d67e9bae174b56b86200626
4
+ data.tar.gz: 39fc4fcd330a596032ceeae0b0fda7941e392f3e2d33a26692cc27a90cea715f
5
+ SHA512:
6
+ metadata.gz: f9b7a469b0d91eb6bf898714c8ede902fd964ef275388700d123a52d079a735617e368060e22620c7718af1d777b749f3a2a0d5e95b4016b0768627f03ca6051
7
+ data.tar.gz: c6bddae3dfbd7fa5d0eaeec5a2fb3dc52ab0808aba5a029f4653c30b46fb9446542e6017bf94c858522dd650c572fcdd44488a650f23e6ba2e136bd9100d2a1d
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,97 @@
1
+ ## Introduction
2
+
3
+ CGI is a large class, providing several categories of methods, many of which
4
+ are mixed in from other modules. Some of the documentation is in this class,
5
+ some in the modules CGI::QueryExtension and CGI::HtmlExtension. See
6
+ CGI::Cookie for specific information on handling cookies, and cgi/session.rb
7
+ (CGI::Session) for information on sessions.
8
+
9
+ For queries, CGI provides methods to get at environmental variables,
10
+ parameters, cookies, and multipart request data. For responses, CGI provides
11
+ methods for writing output and generating HTML.
12
+
13
+ Read on for more details. Examples are provided at the bottom.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'cgi'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install cgi
30
+
31
+ ## Usage
32
+
33
+ ### Get form values
34
+
35
+ ```ruby
36
+ require "cgi"
37
+ cgi = CGI.new
38
+ value = cgi['field_name'] # <== value string for 'field_name'
39
+ # if not 'field_name' included, then return "".
40
+ fields = cgi.keys # <== array of field names
41
+
42
+ # returns true if form has 'field_name'
43
+ cgi.has_key?('field_name')
44
+ cgi.has_key?('field_name')
45
+ cgi.include?('field_name')
46
+ ```
47
+
48
+ CAUTION! cgi['field_name'] returned an Array with the old
49
+ cgi.rb(included in Ruby 1.6)
50
+
51
+ ### Get form values as hash
52
+
53
+ ```ruby
54
+ require "cgi"
55
+ cgi = CGI.new
56
+ params = cgi.params
57
+ ```
58
+
59
+ cgi.params is a hash.
60
+
61
+ ```ruby
62
+ cgi.params['new_field_name'] = ["value"] # add new param
63
+ cgi.params['field_name'] = ["new_value"] # change value
64
+ cgi.params.delete('field_name') # delete param
65
+ cgi.params.clear # delete all params
66
+ ```
67
+
68
+ ### Save form values to file
69
+
70
+ ```ruby
71
+ require "pstore"
72
+ db = PStore.new("query.db")
73
+ db.transaction do
74
+ db["params"] = cgi.params
75
+ end
76
+ ```
77
+
78
+
79
+ ### Restore form values from file
80
+
81
+ ```ruby
82
+ require "pstore"
83
+ db = PStore.new("query.db")
84
+ db.transaction do
85
+ cgi.params = db["params"]
86
+ end
87
+ ```
88
+
89
+ ## Development
90
+
91
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
92
+
93
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
94
+
95
+ ## Contributing
96
+
97
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/cgi.
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Load built-in cgi/escape library
4
+ require 'cgi/escape.jar'
5
+ JRuby::Util.load_ext("org.jruby.ext.cgi.escape.CGIEscape")
data/lib/cgi/cookie.rb ADDED
@@ -0,0 +1,181 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'util'
3
+ class CGI
4
+ # Class representing an HTTP cookie.
5
+ #
6
+ # In addition to its specific fields and methods, a Cookie instance
7
+ # is a delegator to the array of its values.
8
+ #
9
+ # See RFC 2965.
10
+ #
11
+ # == Examples of use
12
+ # cookie1 = CGI::Cookie.new("name", "value1", "value2", ...)
13
+ # cookie1 = CGI::Cookie.new("name" => "name", "value" => "value")
14
+ # cookie1 = CGI::Cookie.new('name' => 'name',
15
+ # 'value' => ['value1', 'value2', ...],
16
+ # 'path' => 'path', # optional
17
+ # 'domain' => 'domain', # optional
18
+ # 'expires' => Time.now, # optional
19
+ # 'secure' => true, # optional
20
+ # 'httponly' => true # optional
21
+ # )
22
+ #
23
+ # cgi.out("cookie" => [cookie1, cookie2]) { "string" }
24
+ #
25
+ # name = cookie1.name
26
+ # values = cookie1.value
27
+ # path = cookie1.path
28
+ # domain = cookie1.domain
29
+ # expires = cookie1.expires
30
+ # secure = cookie1.secure
31
+ # httponly = cookie1.httponly
32
+ #
33
+ # cookie1.name = 'name'
34
+ # cookie1.value = ['value1', 'value2', ...]
35
+ # cookie1.path = 'path'
36
+ # cookie1.domain = 'domain'
37
+ # cookie1.expires = Time.now + 30
38
+ # cookie1.secure = true
39
+ # cookie1.httponly = true
40
+ class Cookie < Array
41
+ @@accept_charset="UTF-8" unless defined?(@@accept_charset)
42
+
43
+ # Create a new CGI::Cookie object.
44
+ #
45
+ # :call-seq:
46
+ # Cookie.new(name_string,*value)
47
+ # Cookie.new(options_hash)
48
+ #
49
+ # +name_string+::
50
+ # The name of the cookie; in this form, there is no #domain or
51
+ # #expiration. The #path is gleaned from the +SCRIPT_NAME+ environment
52
+ # variable, and #secure is false.
53
+ # <tt>*value</tt>::
54
+ # value or list of values of the cookie
55
+ # +options_hash+::
56
+ # A Hash of options to initialize this Cookie. Possible options are:
57
+ #
58
+ # name:: the name of the cookie. Required.
59
+ # value:: the cookie's value or list of values.
60
+ # path:: the path for which this cookie applies. Defaults to
61
+ # the value of the +SCRIPT_NAME+ environment variable.
62
+ # domain:: the domain for which this cookie applies.
63
+ # expires:: the time at which this cookie expires, as a +Time+ object.
64
+ # secure:: whether this cookie is a secure cookie or not (default to
65
+ # false). Secure cookies are only transmitted to HTTPS
66
+ # servers.
67
+ # httponly:: whether this cookie is a HttpOnly cookie or not (default to
68
+ # false). HttpOnly cookies are not available to javascript.
69
+ #
70
+ # These keywords correspond to attributes of the cookie object.
71
+ def initialize(name = "", *value)
72
+ @domain = nil
73
+ @expires = nil
74
+ if name.kind_of?(String)
75
+ @name = name
76
+ @path = (%r|\A(.*/)| =~ ENV["SCRIPT_NAME"] ? $1 : "")
77
+ @secure = false
78
+ @httponly = false
79
+ return super(value)
80
+ end
81
+
82
+ options = name
83
+ unless options.has_key?("name")
84
+ raise ArgumentError, "`name' required"
85
+ end
86
+
87
+ @name = options["name"]
88
+ value = Array(options["value"])
89
+ # simple support for IE
90
+ @path = options["path"] || (%r|\A(.*/)| =~ ENV["SCRIPT_NAME"] ? $1 : "")
91
+ @domain = options["domain"]
92
+ @expires = options["expires"]
93
+ @secure = options["secure"] == true
94
+ @httponly = options["httponly"] == true
95
+
96
+ super(value)
97
+ end
98
+
99
+ # Name of this cookie, as a +String+
100
+ attr_accessor :name
101
+ # Path for which this cookie applies, as a +String+
102
+ attr_accessor :path
103
+ # Domain for which this cookie applies, as a +String+
104
+ attr_accessor :domain
105
+ # Time at which this cookie expires, as a +Time+
106
+ attr_accessor :expires
107
+ # True if this cookie is secure; false otherwise
108
+ attr_reader :secure
109
+ # True if this cookie is httponly; false otherwise
110
+ attr_reader :httponly
111
+
112
+ # Returns the value or list of values for this cookie.
113
+ def value
114
+ self
115
+ end
116
+
117
+ # Replaces the value of this cookie with a new value or list of values.
118
+ def value=(val)
119
+ replace(Array(val))
120
+ end
121
+
122
+ # Set whether the Cookie is a secure cookie or not.
123
+ #
124
+ # +val+ must be a boolean.
125
+ def secure=(val)
126
+ @secure = val if val == true or val == false
127
+ @secure
128
+ end
129
+
130
+ # Set whether the Cookie is a httponly cookie or not.
131
+ #
132
+ # +val+ must be a boolean.
133
+ def httponly=(val)
134
+ @httponly = !!val
135
+ end
136
+
137
+ # Convert the Cookie to its string representation.
138
+ def to_s
139
+ val = collect{|v| CGI.escape(v) }.join("&")
140
+ buf = "#{@name}=#{val}".dup
141
+ buf << "; domain=#{@domain}" if @domain
142
+ buf << "; path=#{@path}" if @path
143
+ buf << "; expires=#{CGI.rfc1123_date(@expires)}" if @expires
144
+ buf << "; secure" if @secure
145
+ buf << "; HttpOnly" if @httponly
146
+ buf
147
+ end
148
+
149
+ # Parse a raw cookie string into a hash of cookie-name=>Cookie
150
+ # pairs.
151
+ #
152
+ # cookies = CGI::Cookie.parse("raw_cookie_string")
153
+ # # { "name1" => cookie1, "name2" => cookie2, ... }
154
+ #
155
+ def self.parse(raw_cookie)
156
+ cookies = Hash.new([])
157
+ return cookies unless raw_cookie
158
+
159
+ raw_cookie.split(/;\s?/).each do |pairs|
160
+ name, values = pairs.split('=',2)
161
+ next unless name and values
162
+ values ||= ""
163
+ values = values.split('&').collect{|v| CGI.unescape(v,@@accept_charset) }
164
+ if cookies.has_key?(name)
165
+ values = cookies[name].value + values
166
+ end
167
+ cookies[name] = Cookie.new(name, *values)
168
+ end
169
+
170
+ cookies
171
+ end
172
+
173
+ # A summary of cookie string.
174
+ def inspect
175
+ "#<CGI::Cookie: #{self.to_s.inspect}>"
176
+ end
177
+
178
+ end # class Cookie
179
+ end
180
+
181
+