rubysl-cgi 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -3
- data/lib/cgi/cookie.rb +32 -27
- data/lib/cgi/core.rb +7 -13
- data/lib/cgi/html.rb +126 -169
- data/lib/cgi/util.rb +26 -22
- data/lib/rubysl/cgi/cgi.rb +20 -1
- data/lib/rubysl/cgi/version.rb +1 -1
- data/rubysl-cgi.gemspec +3 -0
- metadata +28 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b906301d55b0fbfeaea2a18246095462572c1012
|
4
|
+
data.tar.gz: d790a345a6cb9d8c7a3a3db4e8aec259ac02e586
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2b6fcba1c037f2292f90d3f07d80089135546fec6fcea8d1217b1e5a65a708c0fb7fbd4925185a368cc7bd63916d2ed8eda53ab1cde0e74adf00f428c6d7ff3
|
7
|
+
data.tar.gz: 6a81f44358379024fdefbc39526339921e910164e38b598eb0595e047012af9376a37c516f0bd8bd1efda51a15bfdf9ea9cb4f7ef32ffb38b45ca3c346a871c8
|
data/.travis.yml
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
language: ruby
|
2
2
|
env:
|
3
3
|
- RUBYLIB=lib
|
4
|
-
|
4
|
+
- RUBYLIB=
|
5
|
+
script: mspec spec
|
5
6
|
rvm:
|
6
|
-
-
|
7
|
-
- rbx-
|
7
|
+
- 2.0.0
|
8
|
+
- rbx-2.1.1
|
9
|
+
matrix:
|
10
|
+
exclude:
|
11
|
+
- rvm: 2.0.0
|
12
|
+
env: RUBYLIB=lib
|
13
|
+
- rvm: rbx-2.1.1
|
14
|
+
env: RUBYLIB=
|
data/lib/cgi/cookie.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'cgi/util'
|
2
2
|
class CGI
|
3
|
-
@@accept_charset="UTF-8" unless defined?(@@accept_charset)
|
4
3
|
# Class representing an HTTP cookie.
|
5
4
|
#
|
6
5
|
# In addition to its specific fields and methods, a Cookie instance
|
@@ -9,9 +8,9 @@ class CGI
|
|
9
8
|
# See RFC 2965.
|
10
9
|
#
|
11
10
|
# == Examples of use
|
12
|
-
# cookie1 = CGI::Cookie
|
13
|
-
# cookie1 = CGI::Cookie
|
14
|
-
# cookie1 = CGI::Cookie
|
11
|
+
# cookie1 = CGI::Cookie.new("name", "value1", "value2", ...)
|
12
|
+
# cookie1 = CGI::Cookie.new("name" => "name", "value" => "value")
|
13
|
+
# cookie1 = CGI::Cookie.new('name' => 'name',
|
15
14
|
# 'value' => ['value1', 'value2', ...],
|
16
15
|
# 'path' => 'path', # optional
|
17
16
|
# 'domain' => 'domain', # optional
|
@@ -35,6 +34,7 @@ class CGI
|
|
35
34
|
# cookie1.expires = Time.now + 30
|
36
35
|
# cookie1.secure = true
|
37
36
|
class Cookie < Array
|
37
|
+
@@accept_charset="UTF-8" unless defined?(@@accept_charset)
|
38
38
|
|
39
39
|
# Create a new CGI::Cookie object.
|
40
40
|
#
|
@@ -125,7 +125,7 @@ class CGI
|
|
125
125
|
|
126
126
|
# Convert the Cookie to its string representation.
|
127
127
|
def to_s
|
128
|
-
val = collect{|v| CGI
|
128
|
+
val = collect{|v| CGI.escape(v) }.join("&")
|
129
129
|
buf = "#{@name}=#{val}"
|
130
130
|
buf << "; domain=#{@domain}" if @domain
|
131
131
|
buf << "; path=#{@path}" if @path
|
@@ -134,32 +134,37 @@ class CGI
|
|
134
134
|
buf
|
135
135
|
end
|
136
136
|
|
137
|
-
|
137
|
+
# Parse a raw cookie string into a hash of cookie-name=>Cookie
|
138
|
+
# pairs.
|
139
|
+
#
|
140
|
+
# cookies = CGI::Cookie.parse("raw_cookie_string")
|
141
|
+
# # { "name1" => cookie1, "name2" => cookie2, ... }
|
142
|
+
#
|
143
|
+
def self.parse(raw_cookie)
|
144
|
+
cookies = Hash.new([])
|
145
|
+
return cookies unless raw_cookie
|
138
146
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
raw_cookie.split(/[;,]\s?/).each do |pairs|
|
150
|
-
name, values = pairs.split('=',2)
|
151
|
-
next unless name and values
|
152
|
-
name = CGI::unescape(name)
|
153
|
-
values ||= ""
|
154
|
-
values = values.split('&').collect{|v| CGI::unescape(v,@@accept_charset) }
|
155
|
-
if cookies.has_key?(name)
|
156
|
-
values = cookies[name].value + values
|
147
|
+
raw_cookie.split(/[;,]\s?/).each do |pairs|
|
148
|
+
name, values = pairs.split('=',2)
|
149
|
+
next unless name and values
|
150
|
+
name = CGI.unescape(name)
|
151
|
+
values ||= ""
|
152
|
+
values = values.split('&').collect{|v| CGI.unescape(v,@@accept_charset) }
|
153
|
+
if cookies.has_key?(name)
|
154
|
+
values = cookies[name].value + values
|
155
|
+
end
|
156
|
+
cookies[name] = Cookie.new(name, *values)
|
157
157
|
end
|
158
|
-
|
158
|
+
|
159
|
+
cookies
|
160
|
+
end
|
161
|
+
|
162
|
+
# A summary of cookie string.
|
163
|
+
def inspect
|
164
|
+
"#<CGI::Cookie: #{self.to_s.inspect}>"
|
159
165
|
end
|
160
166
|
|
161
|
-
|
162
|
-
end
|
167
|
+
end # class Cookie
|
163
168
|
end
|
164
169
|
|
165
170
|
|
data/lib/cgi/core.rb
CHANGED
@@ -15,7 +15,7 @@ class CGI
|
|
15
15
|
# Standard internet newline sequence
|
16
16
|
EOL = CR + LF
|
17
17
|
|
18
|
-
REVISION = '$Id$' #:nodoc:
|
18
|
+
REVISION = '$Id: core.rb 40787 2013-05-16 10:14:45Z xibbar $' #:nodoc:
|
19
19
|
|
20
20
|
# Whether processing will be required in binary vs text
|
21
21
|
NEEDS_BINMODE = File::BINARY != 0
|
@@ -238,7 +238,7 @@ class CGI
|
|
238
238
|
arr.each {|c| buf << "Set-Cookie: #{c}#{EOL}" }
|
239
239
|
when Hash
|
240
240
|
hash = cookie
|
241
|
-
hash.
|
241
|
+
hash.each_value {|c| buf << "Set-Cookie: #{c}#{EOL}" }
|
242
242
|
end
|
243
243
|
end
|
244
244
|
if @output_cookies
|
@@ -587,14 +587,14 @@ class CGI
|
|
587
587
|
def create_body(is_large) #:nodoc:
|
588
588
|
if is_large
|
589
589
|
require 'tempfile'
|
590
|
-
body = Tempfile.new('CGI', encoding:
|
590
|
+
body = Tempfile.new('CGI', encoding: Encoding::ASCII_8BIT)
|
591
591
|
else
|
592
592
|
begin
|
593
593
|
require 'stringio'
|
594
|
-
body = StringIO.new("".force_encoding(
|
594
|
+
body = StringIO.new("".force_encoding(Encoding::ASCII_8BIT))
|
595
595
|
rescue LoadError
|
596
596
|
require 'tempfile'
|
597
|
-
body = Tempfile.new('CGI', encoding:
|
597
|
+
body = Tempfile.new('CGI', encoding: Encoding::ASCII_8BIT)
|
598
598
|
end
|
599
599
|
end
|
600
600
|
body.binmode if defined? body.binmode
|
@@ -701,9 +701,9 @@ class CGI
|
|
701
701
|
if value
|
702
702
|
return value
|
703
703
|
elsif defined? StringIO
|
704
|
-
StringIO.new("".force_encoding(
|
704
|
+
StringIO.new("".force_encoding(Encoding::ASCII_8BIT))
|
705
705
|
else
|
706
|
-
Tempfile.new("CGI",encoding:
|
706
|
+
Tempfile.new("CGI",encoding: Encoding::ASCII_8BIT)
|
707
707
|
end
|
708
708
|
else
|
709
709
|
str = if value then value.dup else "" end
|
@@ -832,29 +832,23 @@ class CGI
|
|
832
832
|
when "html3"
|
833
833
|
require 'cgi/html'
|
834
834
|
extend Html3
|
835
|
-
element_init()
|
836
835
|
extend HtmlExtension
|
837
836
|
when "html4"
|
838
837
|
require 'cgi/html'
|
839
838
|
extend Html4
|
840
|
-
element_init()
|
841
839
|
extend HtmlExtension
|
842
840
|
when "html4Tr"
|
843
841
|
require 'cgi/html'
|
844
842
|
extend Html4Tr
|
845
|
-
element_init()
|
846
843
|
extend HtmlExtension
|
847
844
|
when "html4Fr"
|
848
845
|
require 'cgi/html'
|
849
846
|
extend Html4Tr
|
850
|
-
element_init()
|
851
847
|
extend Html4Fr
|
852
|
-
element_init()
|
853
848
|
extend HtmlExtension
|
854
849
|
when "html5"
|
855
850
|
require 'cgi/html'
|
856
851
|
extend Html5
|
857
|
-
element_init()
|
858
852
|
extend HtmlExtension
|
859
853
|
end
|
860
854
|
end
|
data/lib/cgi/html.rb
CHANGED
@@ -8,55 +8,62 @@ class CGI
|
|
8
8
|
# Generate code for an element with required start and end tags.
|
9
9
|
#
|
10
10
|
# - -
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
def nn_element(element, attributes = {})
|
12
|
+
s = nOE_element(element, attributes)
|
13
|
+
if block_given?
|
14
|
+
s << yield.to_s
|
15
|
+
end
|
16
|
+
s << "</#{element.upcase}>"
|
17
|
+
end
|
18
|
+
|
19
|
+
def nn_element_def(attributes = {}, &block)
|
20
|
+
nn_element(__callee__, attributes, &block)
|
20
21
|
end
|
21
22
|
|
22
23
|
# Generate code for an empty element.
|
23
24
|
#
|
24
25
|
# - O EMPTY
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
s
|
39
|
-
|
26
|
+
def nOE_element(element, attributes = {})
|
27
|
+
attributes={attributes=>nil} if attributes.kind_of?(String)
|
28
|
+
s = "<#{element.upcase}"
|
29
|
+
attributes.each do|name, value|
|
30
|
+
next unless value
|
31
|
+
s << " "
|
32
|
+
s << CGI::escapeHTML(name.to_s)
|
33
|
+
if value != true
|
34
|
+
s << '="'
|
35
|
+
s << CGI::escapeHTML(value.to_s)
|
36
|
+
s << '"'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
s << ">"
|
40
|
+
end
|
41
|
+
|
42
|
+
def nOE_element_def(attributes = {}, &block)
|
43
|
+
nOE_element(__callee__, attributes, &block)
|
40
44
|
end
|
41
45
|
|
46
|
+
|
42
47
|
# Generate code for an element for which the end (and possibly the
|
43
48
|
# start) tag is optional.
|
44
49
|
#
|
45
50
|
# O O or - O
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
def nO_element(element, attributes = {})
|
52
|
+
s = nOE_element(element, attributes)
|
53
|
+
if block_given?
|
54
|
+
s << yield.to_s
|
55
|
+
s << "</#{element.upcase}>"
|
56
|
+
end
|
57
|
+
s
|
58
|
+
end
|
59
|
+
|
60
|
+
def nO_element_def(attributes = {}, &block)
|
61
|
+
nO_element(__callee__, attributes, &block)
|
54
62
|
end
|
55
63
|
|
56
64
|
end # TagMaker
|
57
65
|
|
58
66
|
|
59
|
-
#
|
60
67
|
# Mixin module providing HTML generation methods.
|
61
68
|
#
|
62
69
|
# For example,
|
@@ -92,11 +99,7 @@ class CGI
|
|
92
99
|
else
|
93
100
|
href
|
94
101
|
end
|
95
|
-
|
96
|
-
super(attributes){ yield }
|
97
|
-
else
|
98
|
-
super(attributes)
|
99
|
-
end
|
102
|
+
super(attributes)
|
100
103
|
end
|
101
104
|
|
102
105
|
# Generate a Document Base URI element as a String.
|
@@ -114,11 +117,7 @@ class CGI
|
|
114
117
|
else
|
115
118
|
href
|
116
119
|
end
|
117
|
-
|
118
|
-
super(attributes){ yield }
|
119
|
-
else
|
120
|
-
super(attributes)
|
121
|
-
end
|
120
|
+
super(attributes)
|
122
121
|
end
|
123
122
|
|
124
123
|
# Generate a BlockQuote element as a string.
|
@@ -137,11 +136,7 @@ class CGI
|
|
137
136
|
else
|
138
137
|
cite
|
139
138
|
end
|
140
|
-
|
141
|
-
super(attributes){ yield }
|
142
|
-
else
|
143
|
-
super(attributes)
|
144
|
-
end
|
139
|
+
super(attributes)
|
145
140
|
end
|
146
141
|
|
147
142
|
|
@@ -161,11 +156,7 @@ class CGI
|
|
161
156
|
else
|
162
157
|
align
|
163
158
|
end
|
164
|
-
|
165
|
-
super(attributes){ yield }
|
166
|
-
else
|
167
|
-
super(attributes)
|
168
|
-
end
|
159
|
+
super(attributes)
|
169
160
|
end
|
170
161
|
|
171
162
|
|
@@ -428,11 +419,7 @@ class CGI
|
|
428
419
|
buf << doctype
|
429
420
|
end
|
430
421
|
|
431
|
-
|
432
|
-
buf << super(attributes){ yield }
|
433
|
-
else
|
434
|
-
buf << super(attributes)
|
435
|
-
end
|
422
|
+
buf << super(attributes)
|
436
423
|
|
437
424
|
if pretty
|
438
425
|
CGI::pretty(buf, pretty)
|
@@ -824,11 +811,7 @@ class CGI
|
|
824
811
|
else
|
825
812
|
name
|
826
813
|
end
|
827
|
-
|
828
|
-
super(attributes){ yield }
|
829
|
-
else
|
830
|
-
super(attributes)
|
831
|
-
end
|
814
|
+
super(attributes)
|
832
815
|
end
|
833
816
|
|
834
817
|
end # HtmlExtension
|
@@ -836,50 +819,38 @@ class CGI
|
|
836
819
|
|
837
820
|
# Mixin module for HTML version 3 generation methods.
|
838
821
|
module Html3 # :nodoc:
|
822
|
+
include TagMaker
|
839
823
|
|
840
824
|
# The DOCTYPE declaration for this version of HTML
|
841
825
|
def doctype
|
842
826
|
%|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">|
|
843
827
|
end
|
844
828
|
|
845
|
-
|
846
|
-
def element_init
|
847
|
-
extend TagMaker
|
848
|
-
return if defined?(html)
|
849
|
-
methods = ""
|
829
|
+
instance_method(:nn_element_def).tap do |m|
|
850
830
|
# - -
|
851
831
|
for element in %w[ A TT I B U STRIKE BIG SMALL SUB SUP EM STRONG
|
852
832
|
DFN CODE SAMP KBD VAR CITE FONT ADDRESS DIV CENTER MAP
|
853
833
|
APPLET PRE XMP LISTING DL OL UL DIR MENU SELECT TABLE TITLE
|
854
834
|
STYLE SCRIPT H1 H2 H3 H4 H5 H6 TEXTAREA FORM BLOCKQUOTE
|
855
835
|
CAPTION ]
|
856
|
-
|
857
|
-
def #{element.downcase}(attributes = {})
|
858
|
-
BEGIN
|
859
|
-
end
|
860
|
-
END
|
836
|
+
define_method(element.downcase, m)
|
861
837
|
end
|
838
|
+
end
|
862
839
|
|
840
|
+
instance_method(:nOE_element_def).tap do |m|
|
863
841
|
# - O EMPTY
|
864
842
|
for element in %w[ IMG BASE BASEFONT BR AREA LINK PARAM HR INPUT
|
865
843
|
ISINDEX META ]
|
866
|
-
|
867
|
-
def #{element.downcase}(attributes = {})
|
868
|
-
BEGIN
|
869
|
-
end
|
870
|
-
END
|
844
|
+
define_method(element.downcase, m)
|
871
845
|
end
|
846
|
+
end
|
872
847
|
|
848
|
+
instance_method(:nO_element_def).tap do |m|
|
873
849
|
# O O or - O
|
874
850
|
for element in %w[ HTML HEAD BODY P PLAINTEXT DT DD LI OPTION TR
|
875
851
|
TH TD ]
|
876
|
-
|
877
|
-
def #{element.downcase}(attributes = {})
|
878
|
-
BEGIN
|
879
|
-
end
|
880
|
-
END
|
852
|
+
define_method(element.downcase, m)
|
881
853
|
end
|
882
|
-
eval(methods)
|
883
854
|
end
|
884
855
|
|
885
856
|
end # Html3
|
@@ -887,6 +858,7 @@ class CGI
|
|
887
858
|
|
888
859
|
# Mixin module for HTML version 4 generation methods.
|
889
860
|
module Html4 # :nodoc:
|
861
|
+
include TagMaker
|
890
862
|
|
891
863
|
# The DOCTYPE declaration for this version of HTML
|
892
864
|
def doctype
|
@@ -894,42 +866,30 @@ class CGI
|
|
894
866
|
end
|
895
867
|
|
896
868
|
# Initialise the HTML generation methods for this version.
|
897
|
-
|
898
|
-
|
899
|
-
return if defined?(html)
|
900
|
-
methods = ""
|
901
|
-
# - -
|
869
|
+
# - -
|
870
|
+
instance_method(:nn_element_def).tap do |m|
|
902
871
|
for element in %w[ TT I B BIG SMALL EM STRONG DFN CODE SAMP KBD
|
903
872
|
VAR CITE ABBR ACRONYM SUB SUP SPAN BDO ADDRESS DIV MAP OBJECT
|
904
873
|
H1 H2 H3 H4 H5 H6 PRE Q INS DEL DL OL UL LABEL SELECT OPTGROUP
|
905
874
|
FIELDSET LEGEND BUTTON TABLE TITLE STYLE SCRIPT NOSCRIPT
|
906
875
|
TEXTAREA FORM A BLOCKQUOTE CAPTION ]
|
907
|
-
|
908
|
-
def #{element.downcase}(attributes = {})
|
909
|
-
BEGIN
|
910
|
-
end
|
911
|
-
END
|
876
|
+
define_method(element.downcase, m)
|
912
877
|
end
|
878
|
+
end
|
913
879
|
|
914
|
-
|
880
|
+
# - O EMPTY
|
881
|
+
instance_method(:nOE_element_def).tap do |m|
|
915
882
|
for element in %w[ IMG BASE BR AREA LINK PARAM HR INPUT COL META ]
|
916
|
-
|
917
|
-
def #{element.downcase}(attributes = {})
|
918
|
-
BEGIN
|
919
|
-
end
|
920
|
-
END
|
883
|
+
define_method(element.downcase, m)
|
921
884
|
end
|
885
|
+
end
|
922
886
|
|
923
|
-
|
887
|
+
# O O or - O
|
888
|
+
instance_method(:nO_element_def).tap do |m|
|
924
889
|
for element in %w[ HTML BODY P DT DD LI OPTION THEAD TFOOT TBODY
|
925
890
|
COLGROUP TR TH TD HEAD ]
|
926
|
-
|
927
|
-
def #{element.downcase}(attributes = {})
|
928
|
-
BEGIN
|
929
|
-
end
|
930
|
-
END
|
891
|
+
define_method(element.downcase, m)
|
931
892
|
end
|
932
|
-
eval(methods)
|
933
893
|
end
|
934
894
|
|
935
895
|
end # Html4
|
@@ -937,6 +897,7 @@ class CGI
|
|
937
897
|
|
938
898
|
# Mixin module for HTML version 4 transitional generation methods.
|
939
899
|
module Html4Tr # :nodoc:
|
900
|
+
include TagMaker
|
940
901
|
|
941
902
|
# The DOCTYPE declaration for this version of HTML
|
942
903
|
def doctype
|
@@ -944,44 +905,32 @@ class CGI
|
|
944
905
|
end
|
945
906
|
|
946
907
|
# Initialise the HTML generation methods for this version.
|
947
|
-
|
948
|
-
|
949
|
-
return if defined?(html)
|
950
|
-
methods = ""
|
951
|
-
# - -
|
908
|
+
# - -
|
909
|
+
instance_method(:nn_element_def).tap do |m|
|
952
910
|
for element in %w[ TT I B U S STRIKE BIG SMALL EM STRONG DFN
|
953
911
|
CODE SAMP KBD VAR CITE ABBR ACRONYM FONT SUB SUP SPAN BDO
|
954
912
|
ADDRESS DIV CENTER MAP OBJECT APPLET H1 H2 H3 H4 H5 H6 PRE Q
|
955
913
|
INS DEL DL OL UL DIR MENU LABEL SELECT OPTGROUP FIELDSET
|
956
914
|
LEGEND BUTTON TABLE IFRAME NOFRAMES TITLE STYLE SCRIPT
|
957
915
|
NOSCRIPT TEXTAREA FORM A BLOCKQUOTE CAPTION ]
|
958
|
-
|
959
|
-
def #{element.downcase}(attributes = {})
|
960
|
-
BEGIN
|
961
|
-
end
|
962
|
-
END
|
916
|
+
define_method(element.downcase, m)
|
963
917
|
end
|
918
|
+
end
|
964
919
|
|
965
|
-
|
920
|
+
# - O EMPTY
|
921
|
+
instance_method(:nOE_element_def).tap do |m|
|
966
922
|
for element in %w[ IMG BASE BASEFONT BR AREA LINK PARAM HR INPUT
|
967
923
|
COL ISINDEX META ]
|
968
|
-
|
969
|
-
def #{element.downcase}(attributes = {})
|
970
|
-
BEGIN
|
971
|
-
end
|
972
|
-
END
|
924
|
+
define_method(element.downcase, m)
|
973
925
|
end
|
926
|
+
end
|
974
927
|
|
975
|
-
|
928
|
+
# O O or - O
|
929
|
+
instance_method(:nO_element_def).tap do |m|
|
976
930
|
for element in %w[ HTML BODY P DT DD LI OPTION THEAD TFOOT TBODY
|
977
931
|
COLGROUP TR TH TD HEAD ]
|
978
|
-
|
979
|
-
def #{element.downcase}(attributes = {})
|
980
|
-
BEGIN
|
981
|
-
end
|
982
|
-
END
|
932
|
+
define_method(element.downcase, m)
|
983
933
|
end
|
984
|
-
eval(methods)
|
985
934
|
end
|
986
935
|
|
987
936
|
end # Html4Tr
|
@@ -989,6 +938,7 @@ class CGI
|
|
989
938
|
|
990
939
|
# Mixin module for generating HTML version 4 with framesets.
|
991
940
|
module Html4Fr # :nodoc:
|
941
|
+
include TagMaker
|
992
942
|
|
993
943
|
# The DOCTYPE declaration for this version of HTML
|
994
944
|
def doctype
|
@@ -996,27 +946,18 @@ class CGI
|
|
996
946
|
end
|
997
947
|
|
998
948
|
# Initialise the HTML generation methods for this version.
|
999
|
-
|
1000
|
-
|
1001
|
-
methods = ""
|
1002
|
-
# - -
|
949
|
+
# - -
|
950
|
+
instance_method(:nn_element_def).tap do |m|
|
1003
951
|
for element in %w[ FRAMESET ]
|
1004
|
-
|
1005
|
-
def #{element.downcase}(attributes = {})
|
1006
|
-
BEGIN
|
1007
|
-
end
|
1008
|
-
END
|
952
|
+
define_method(element.downcase, m)
|
1009
953
|
end
|
954
|
+
end
|
1010
955
|
|
1011
|
-
|
956
|
+
# - O EMPTY
|
957
|
+
instance_method(:nOE_element_def).tap do |m|
|
1012
958
|
for element in %w[ FRAME ]
|
1013
|
-
|
1014
|
-
def #{element.downcase}(attributes = {})
|
1015
|
-
BEGIN
|
1016
|
-
end
|
1017
|
-
END
|
959
|
+
define_method(element.downcase, m)
|
1018
960
|
end
|
1019
|
-
eval(methods)
|
1020
961
|
end
|
1021
962
|
|
1022
963
|
end # Html4Fr
|
@@ -1024,6 +965,7 @@ class CGI
|
|
1024
965
|
|
1025
966
|
# Mixin module for HTML version 5 generation methods.
|
1026
967
|
module Html5 # :nodoc:
|
968
|
+
include TagMaker
|
1027
969
|
|
1028
970
|
# The DOCTYPE declaration for this version of HTML
|
1029
971
|
def doctype
|
@@ -1031,11 +973,8 @@ class CGI
|
|
1031
973
|
end
|
1032
974
|
|
1033
975
|
# Initialise the HTML generation methods for this version.
|
1034
|
-
|
1035
|
-
|
1036
|
-
return if defined?(html)
|
1037
|
-
methods = ""
|
1038
|
-
# - -
|
976
|
+
# - -
|
977
|
+
instance_method(:nn_element_def).tap do |m|
|
1039
978
|
for element in %w[ SECTION NAV ARTICLE ASIDE HGROUP HEADER
|
1040
979
|
FOOTER FIGURE FIGCAPTION S TIME U MARK RUBY BDI IFRAME
|
1041
980
|
VIDEO AUDIO CANVAS DATALIST OUTPUT PROGRESS METER DETAILS
|
@@ -1044,34 +983,52 @@ class CGI
|
|
1044
983
|
H1 H2 H3 H4 H5 H6 PRE Q INS DEL DL OL UL LABEL SELECT
|
1045
984
|
FIELDSET LEGEND BUTTON TABLE TITLE STYLE SCRIPT NOSCRIPT
|
1046
985
|
TEXTAREA FORM A BLOCKQUOTE CAPTION ]
|
1047
|
-
|
1048
|
-
def #{element.downcase}(attributes = {})
|
1049
|
-
BEGIN
|
1050
|
-
end
|
1051
|
-
END
|
986
|
+
define_method(element.downcase, m)
|
1052
987
|
end
|
988
|
+
end
|
1053
989
|
|
1054
|
-
|
990
|
+
# - O EMPTY
|
991
|
+
instance_method(:nOE_element_def).tap do |m|
|
1055
992
|
for element in %w[ IMG BASE BR AREA LINK PARAM HR INPUT COL META
|
1056
993
|
COMMAND EMBED KEYGEN SOURCE TRACK WBR ]
|
1057
|
-
|
1058
|
-
def #{element.downcase}(attributes = {})
|
1059
|
-
BEGIN
|
1060
|
-
end
|
1061
|
-
END
|
994
|
+
define_method(element.downcase, m)
|
1062
995
|
end
|
996
|
+
end
|
1063
997
|
|
1064
|
-
|
998
|
+
# O O or - O
|
999
|
+
instance_method(:nO_element_def).tap do |m|
|
1065
1000
|
for element in %w[ HTML HEAD BODY P DT DD LI OPTION THEAD TFOOT TBODY
|
1066
1001
|
OPTGROUP COLGROUP RT RP TR TH TD ]
|
1067
|
-
|
1068
|
-
def #{element.downcase}(attributes = {})
|
1069
|
-
BEGIN
|
1070
|
-
end
|
1071
|
-
END
|
1002
|
+
define_method(element.downcase, m)
|
1072
1003
|
end
|
1073
|
-
eval(methods)
|
1074
1004
|
end
|
1075
1005
|
|
1076
1006
|
end # Html5
|
1007
|
+
|
1008
|
+
class HTML3
|
1009
|
+
include Html3
|
1010
|
+
include HtmlExtension
|
1011
|
+
end
|
1012
|
+
|
1013
|
+
class HTML4
|
1014
|
+
include Html4
|
1015
|
+
include HtmlExtension
|
1016
|
+
end
|
1017
|
+
|
1018
|
+
class HTML4Tr
|
1019
|
+
include Html4Tr
|
1020
|
+
include HtmlExtension
|
1021
|
+
end
|
1022
|
+
|
1023
|
+
class HTML4Fr
|
1024
|
+
include Html4Tr
|
1025
|
+
include Html4Fr
|
1026
|
+
include HtmlExtension
|
1027
|
+
end
|
1028
|
+
|
1029
|
+
class HTML5
|
1030
|
+
include Html5
|
1031
|
+
include HtmlExtension
|
1032
|
+
end
|
1033
|
+
|
1077
1034
|
end
|
data/lib/cgi/util.rb
CHANGED
@@ -1,21 +1,22 @@
|
|
1
|
-
class CGI
|
1
|
+
class CGI; module Util; end; extend Util; end
|
2
|
+
module CGI::Util
|
2
3
|
@@accept_charset="UTF-8" unless defined?(@@accept_charset)
|
3
4
|
# URL-encode a string.
|
4
5
|
# url_encoded_string = CGI::escape("'Stop!' said Fred")
|
5
6
|
# # => "%27Stop%21%27+said+Fred"
|
6
|
-
def
|
7
|
+
def escape(string)
|
7
8
|
encoding = string.encoding
|
8
|
-
string.
|
9
|
-
'%' +
|
9
|
+
string.b.gsub(/([^ a-zA-Z0-9_.-]+)/) do |m|
|
10
|
+
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
|
10
11
|
end.tr(' ', '+').force_encoding(encoding)
|
11
12
|
end
|
12
13
|
|
13
14
|
# URL-decode a string with encoding(optional).
|
14
15
|
# string = CGI::unescape("%27Stop%21%27+said+Fred")
|
15
16
|
# # => "'Stop!' said Fred"
|
16
|
-
def
|
17
|
-
str=string.tr('+', ' ').
|
18
|
-
[
|
17
|
+
def unescape(string,encoding=@@accept_charset)
|
18
|
+
str=string.tr('+', ' ').b.gsub(/((?:%[0-9a-fA-F]{2})+)/) do |m|
|
19
|
+
[m.delete('%')].pack('H*')
|
19
20
|
end.force_encoding(encoding)
|
20
21
|
str.valid_encoding? ? str : str.force_encoding(string.encoding)
|
21
22
|
end
|
@@ -32,18 +33,19 @@ class CGI
|
|
32
33
|
# Escape special characters in HTML, namely &\"<>
|
33
34
|
# CGI::escapeHTML('Usage: foo "bar" <baz>')
|
34
35
|
# # => "Usage: foo "bar" <baz>"
|
35
|
-
def
|
36
|
+
def escapeHTML(string)
|
36
37
|
string.gsub(/['&\"<>]/, TABLE_FOR_ESCAPE_HTML__)
|
37
38
|
end
|
38
39
|
|
39
40
|
# Unescape a string that has been HTML-escaped
|
40
41
|
# CGI::unescapeHTML("Usage: foo "bar" <baz>")
|
41
42
|
# # => "Usage: foo \"bar\" <baz>"
|
42
|
-
def
|
43
|
+
def unescapeHTML(string)
|
44
|
+
return string unless string.include? '&'
|
43
45
|
enc = string.encoding
|
44
|
-
if [Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE].include?(enc)
|
46
|
+
if enc != Encoding::UTF_8 && [Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE].include?(enc)
|
45
47
|
return string.gsub(Regexp.new('&(apos|amp|quot|gt|lt|#[0-9]+|#x[0-9A-Fa-f]+);'.encode(enc))) do
|
46
|
-
case $1.encode(
|
48
|
+
case $1.encode(Encoding::US_ASCII)
|
47
49
|
when 'apos' then "'".encode(enc)
|
48
50
|
when 'amp' then '&'.encode(enc)
|
49
51
|
when 'quot' then '"'.encode(enc)
|
@@ -88,12 +90,12 @@ class CGI
|
|
88
90
|
end
|
89
91
|
|
90
92
|
# Synonym for CGI::escapeHTML(str)
|
91
|
-
def
|
93
|
+
def escape_html(str)
|
92
94
|
escapeHTML(str)
|
93
95
|
end
|
94
96
|
|
95
97
|
# Synonym for CGI::unescapeHTML(str)
|
96
|
-
def
|
98
|
+
def unescape_html(str)
|
97
99
|
unescapeHTML(str)
|
98
100
|
end
|
99
101
|
|
@@ -110,7 +112,7 @@ class CGI
|
|
110
112
|
#
|
111
113
|
# print CGI::escapeElement('<BR><A HREF="url"></A>', ["A", "IMG"])
|
112
114
|
# # "<BR><A HREF="url"></A>"
|
113
|
-
def
|
115
|
+
def escapeElement(string, *elements)
|
114
116
|
elements = elements[0] if elements[0].kind_of?(Array)
|
115
117
|
unless elements.empty?
|
116
118
|
string.gsub(/<\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?>/i) do
|
@@ -130,11 +132,11 @@ class CGI
|
|
130
132
|
# print CGI::unescapeElement(
|
131
133
|
# CGI::escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
|
132
134
|
# # "<BR><A HREF="url"></A>"
|
133
|
-
def
|
135
|
+
def unescapeElement(string, *elements)
|
134
136
|
elements = elements[0] if elements[0].kind_of?(Array)
|
135
137
|
unless elements.empty?
|
136
138
|
string.gsub(/<\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?>/i) do
|
137
|
-
|
139
|
+
unescapeHTML($&)
|
138
140
|
end
|
139
141
|
else
|
140
142
|
string
|
@@ -142,12 +144,12 @@ class CGI
|
|
142
144
|
end
|
143
145
|
|
144
146
|
# Synonym for CGI::escapeElement(str)
|
145
|
-
def
|
147
|
+
def escape_element(str)
|
146
148
|
escapeElement(str)
|
147
149
|
end
|
148
150
|
|
149
151
|
# Synonym for CGI::unescapeElement(str)
|
150
|
-
def
|
152
|
+
def unescape_element(str)
|
151
153
|
unescapeElement(str)
|
152
154
|
end
|
153
155
|
|
@@ -161,11 +163,11 @@ class CGI
|
|
161
163
|
#
|
162
164
|
# CGI::rfc1123_date(Time.now)
|
163
165
|
# # Sat, 01 Jan 2000 00:00:00 GMT
|
164
|
-
def
|
166
|
+
def rfc1123_date(time)
|
165
167
|
t = time.clone.gmtime
|
166
168
|
return format("%s, %.2d %s %.4d %.2d:%.2d:%.2d GMT",
|
167
|
-
|
168
|
-
|
169
|
+
RFC822_DAYS[t.wday], t.day, RFC822_MONTHS[t.month-1], t.year,
|
170
|
+
t.hour, t.min, t.sec)
|
169
171
|
end
|
170
172
|
|
171
173
|
# Prettify (indent) an HTML string.
|
@@ -185,7 +187,7 @@ class CGI
|
|
185
187
|
# # </BODY>
|
186
188
|
# # </HTML>
|
187
189
|
#
|
188
|
-
def
|
190
|
+
def pretty(string, shift = " ")
|
189
191
|
lines = string.gsub(/(?!\A)<.*?>/m, "\n\\0").gsub(/<.*?>(?!\n)/m, "\\0\n")
|
190
192
|
end_pos = 0
|
191
193
|
while end_pos = lines.index(/^<\/(\w+)/, end_pos)
|
@@ -195,4 +197,6 @@ class CGI
|
|
195
197
|
end
|
196
198
|
lines.gsub(/^((?:#{Regexp::quote(shift)})*)__(?=<\/?\w)/, '\1')
|
197
199
|
end
|
200
|
+
|
201
|
+
alias h escapeHTML
|
198
202
|
end
|
data/lib/rubysl/cgi/cgi.rb
CHANGED
@@ -143,6 +143,11 @@ raise "Please, use ruby 1.9.0 or later." if RUBY_VERSION < "1.9.0"
|
|
143
143
|
# take particular attributes where the attributes can be directly specified
|
144
144
|
# as arguments, rather than via a hash.
|
145
145
|
#
|
146
|
+
# === Utility HTML escape and other methods like a function.
|
147
|
+
#
|
148
|
+
# There are some utility tool defined in cgi/util.rb .
|
149
|
+
# And when include, you can use utility methods like a function.
|
150
|
+
#
|
146
151
|
# == Examples of use
|
147
152
|
#
|
148
153
|
# === Get form values
|
@@ -159,7 +164,7 @@ raise "Please, use ruby 1.9.0 or later." if RUBY_VERSION < "1.9.0"
|
|
159
164
|
# cgi.include?('field_name')
|
160
165
|
#
|
161
166
|
# CAUTION! cgi['field_name'] returned an Array with the old
|
162
|
-
# cgi.rb(included in
|
167
|
+
# cgi.rb(included in Ruby 1.6)
|
163
168
|
#
|
164
169
|
# === Get form values as hash
|
165
170
|
#
|
@@ -268,6 +273,20 @@ raise "Please, use ruby 1.9.0 or later." if RUBY_VERSION < "1.9.0"
|
|
268
273
|
# CGI.new("html4Fr") # html4.01 Frameset
|
269
274
|
# CGI.new("html5") # html5
|
270
275
|
#
|
276
|
+
# === Some utility methods
|
277
|
+
#
|
278
|
+
# require 'cgi/util'
|
279
|
+
# CGI.escapeHTML('Usage: foo "bar" <baz>')
|
280
|
+
#
|
281
|
+
#
|
282
|
+
# === Some utility methods like a function
|
283
|
+
#
|
284
|
+
# require 'cgi/util'
|
285
|
+
# include CGI::Util
|
286
|
+
# escapeHTML('Usage: foo "bar" <baz>')
|
287
|
+
# h('Usage: foo "bar" <baz>') # alias
|
288
|
+
#
|
289
|
+
#
|
271
290
|
|
272
291
|
class CGI
|
273
292
|
end
|
data/lib/rubysl/cgi/version.rb
CHANGED
data/rubysl-cgi.gemspec
CHANGED
@@ -16,7 +16,10 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
|
+
spec.required_ruby_version = "~> 2.0"
|
20
|
+
|
19
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
20
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
21
23
|
spec.add_development_dependency "mspec", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rubysl-prettyprint", "~> 2.0"
|
22
25
|
end
|
metadata
CHANGED
@@ -1,57 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubysl-cgi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Shirai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09
|
11
|
+
date: 2013-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: mspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.5'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubysl-prettyprint
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
55
69
|
description: Ruby standard library cgi.
|
56
70
|
email:
|
57
71
|
- brixen@gmail.com
|
@@ -59,8 +73,8 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .travis.yml
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
64
78
|
- Gemfile
|
65
79
|
- LICENSE
|
66
80
|
- LICENSE.txt
|
@@ -176,12 +190,12 @@ require_paths:
|
|
176
190
|
- lib
|
177
191
|
required_ruby_version: !ruby/object:Gem::Requirement
|
178
192
|
requirements:
|
179
|
-
- -
|
193
|
+
- - "~>"
|
180
194
|
- !ruby/object:Gem::Version
|
181
|
-
version: '0'
|
195
|
+
version: '2.0'
|
182
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
197
|
requirements:
|
184
|
-
- -
|
198
|
+
- - ">="
|
185
199
|
- !ruby/object:Gem::Version
|
186
200
|
version: '0'
|
187
201
|
requirements: []
|
@@ -282,3 +296,4 @@ test_files:
|
|
282
296
|
- spec/unescapeElement_spec.rb
|
283
297
|
- spec/unescapeHTML_spec.rb
|
284
298
|
- spec/unescape_spec.rb
|
299
|
+
has_rdoc:
|