uri-component 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/uri/component/path.rb +5 -1
- data/lib/uri/component/query.rb +76 -1
- data/lib/uri/component/userinfo.rb +7 -7
- data/lib/uri/component/version.rb +1 -1
- metadata +2 -2
data/lib/uri/component/path.rb
CHANGED
@@ -41,10 +41,14 @@ module URI
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
def escape(v)
|
45
|
+
return URI.escape(v, RE_UNSAFE)
|
46
|
+
end
|
47
|
+
|
44
48
|
def to_uri
|
45
49
|
return '' if @nodes.empty?
|
46
50
|
return '/' + @nodes.map do |node|
|
47
|
-
|
51
|
+
self.escape(node)
|
48
52
|
end.join('/')
|
49
53
|
end
|
50
54
|
alias to_s to_uri
|
data/lib/uri/component/query.rb
CHANGED
@@ -10,6 +10,81 @@ require 'cgi'
|
|
10
10
|
|
11
11
|
module URI
|
12
12
|
module Component
|
13
|
+
class QueryParamsHash < Hash #:nodoc:
|
14
|
+
def convert_key(key)
|
15
|
+
return key.kind_of?(String) ? key : key.to_s
|
16
|
+
end
|
17
|
+
def [](key)
|
18
|
+
super(self.convert_key(key))
|
19
|
+
end
|
20
|
+
def fetch(key, default = nil)
|
21
|
+
super(self.convert_key(key), default)
|
22
|
+
end
|
23
|
+
|
24
|
+
def values(key = nil)
|
25
|
+
return key ? self[key] : super
|
26
|
+
end
|
27
|
+
|
28
|
+
def values=(key, values)
|
29
|
+
self[key] = values
|
30
|
+
end
|
31
|
+
|
32
|
+
def value(key)
|
33
|
+
return self[key][0]
|
34
|
+
end
|
35
|
+
|
36
|
+
def value=(key, value)
|
37
|
+
self[key] = value
|
38
|
+
end
|
39
|
+
|
40
|
+
def values_at(*keys)
|
41
|
+
super(*keys.map {|key| self.convert_key(key)})
|
42
|
+
end
|
43
|
+
|
44
|
+
def []=(key, values)
|
45
|
+
values = [values] unless values.kind_of?(Array)
|
46
|
+
super(self.convert_key(key), values)
|
47
|
+
end
|
48
|
+
def store(key, values)
|
49
|
+
self[key] = values
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete(key)
|
53
|
+
super(self.convert_key(key))
|
54
|
+
end
|
55
|
+
|
56
|
+
def has_key?(key)
|
57
|
+
super(self.convert_key(key))
|
58
|
+
end
|
59
|
+
alias :include? :has_key?
|
60
|
+
alias :key? :has_key?
|
61
|
+
alias :member? :has_key?
|
62
|
+
|
63
|
+
def merge(hash)
|
64
|
+
hash_new = self.class.new
|
65
|
+
hash.each do |key, value|
|
66
|
+
hash_new[key] = value
|
67
|
+
end
|
68
|
+
return hash_new
|
69
|
+
end
|
70
|
+
|
71
|
+
def merge!(hash)
|
72
|
+
hash.each do |key, value|
|
73
|
+
self[key] = value
|
74
|
+
end
|
75
|
+
return self
|
76
|
+
end
|
77
|
+
alias :update :merge!
|
78
|
+
|
79
|
+
def replace(hash)
|
80
|
+
self.clear
|
81
|
+
hash.each do |key, value|
|
82
|
+
self[key] = value
|
83
|
+
end
|
84
|
+
return self
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
13
88
|
## Handle a query component in an URI as an object
|
14
89
|
class Query
|
15
90
|
#:stopdoc:
|
@@ -26,7 +101,7 @@ module URI
|
|
26
101
|
raise InvalidURIError, "bad Query component for URI: #{query_str}"
|
27
102
|
end
|
28
103
|
|
29
|
-
@params =
|
104
|
+
@params = QueryParamsHash.new
|
30
105
|
@params.default_proc = Proc.new {|hash, key|
|
31
106
|
hash[key] = [] unless hash.key?(key)
|
32
107
|
}
|
@@ -26,7 +26,7 @@ module URI
|
|
26
26
|
UserInfoMixin.__send__(:included, klass)
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def escape(v)
|
30
30
|
return URI.escape(v, RE_UNSAFE)
|
31
31
|
end
|
32
32
|
|
@@ -80,9 +80,9 @@ module URI
|
|
80
80
|
return nil unless @user
|
81
81
|
|
82
82
|
info_str = ''
|
83
|
-
info_str += self.
|
84
|
-
info_str += @user ? self.
|
85
|
-
info_str += ':' + self.
|
83
|
+
info_str += self.escape(@domain) + ';' if @domain
|
84
|
+
info_str += @user ? self.escape(@user) : '';
|
85
|
+
info_str += ':' + self.escape(@password) if @password
|
86
86
|
return info_str
|
87
87
|
end
|
88
88
|
alias to_s to_uri
|
@@ -113,8 +113,8 @@ module URI
|
|
113
113
|
return nil unless user
|
114
114
|
|
115
115
|
domain = @userinfo_component.domain
|
116
|
-
user_uri = domain ?
|
117
|
-
user_uri +=
|
116
|
+
user_uri = domain ? @userinfo_component.escape(domain) + ';' : ''
|
117
|
+
user_uri += @userinfo_component.escape(user)
|
118
118
|
return user_uri
|
119
119
|
end
|
120
120
|
|
@@ -130,7 +130,7 @@ module URI
|
|
130
130
|
|
131
131
|
def password
|
132
132
|
pass = @userinfo_component.password
|
133
|
-
return pass ?
|
133
|
+
return pass ? @userinfo_component.escape(pass) : nil
|
134
134
|
end
|
135
135
|
|
136
136
|
def password=(pass_uri)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uri-component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-05 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Handle URI components as an object
|
15
15
|
email:
|