diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-05-27 17:48:54 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-05-27 17:48:54 +0000 |
commit | 0fd221bd781a28f46794d250236ed21da5ae1022 (patch) | |
tree | 28274c5ff1d7415119bbcd7ee8ff9380ce33094c /lib/uri | |
parent | 7afe0c92ea9f4e363429f3209567b4bc3de302db (diff) |
* lib/uri: don't set @parser if it is DEFAULT_PARSER for marshaling
URI objects between Ruby 1.8 and Ruby 1.9.
[ruby-dev:38377]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/uri')
-rw-r--r-- | lib/uri/generic.rb | 53 | ||||
-rw-r--r-- | lib/uri/mailto.rb | 14 |
2 files changed, 37 insertions, 30 deletions
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index adc3805265..fd01f89797 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -73,7 +73,7 @@ module URI if args.kind_of?(Array) return self.build(args.collect{|x| if x - @parser.escape(x) + parser.escape(x) else x end @@ -82,7 +82,7 @@ module URI tmp = {} args.each do |key, value| tmp[key] = if value - @parser.escape(value) + parser.escape(value) else value end @@ -121,7 +121,7 @@ module URI "expected Array of or Hash of components of #{self.class} (#{self.class.component.join(', ')})" end - tmp << DEFAULT_PARSER + tmp << nil tmp << true return self.new(*tmp) end @@ -172,7 +172,7 @@ module URI @opaque = nil @registry = nil @fragment = nil - @parser = parser + @parser = parser == DEFAULT_PARSER ? nil : parser if arg_check self.scheme = scheme @@ -212,7 +212,14 @@ module URI attr_reader :query attr_reader :opaque attr_reader :fragment - attr_reader :parser + + def parser + if !defined?(@parser) || !@parser + DEFAULT_PARSER + else + @parser || DEFAULT_PARSER + end + end # replace self by other URI object def replace!(oth) @@ -231,7 +238,7 @@ module URI end def check_scheme(v) - if v && @parser.regexp[:SCHEME] !~ v + if v && parser.regexp[:SCHEME] !~ v raise InvalidComponentError, "bad component(expected scheme component): #{v}" end @@ -270,7 +277,7 @@ module URI return v unless v - if @parser.regexp[:USERINFO] !~ v + if parser.regexp[:USERINFO] !~ v raise InvalidComponentError, "bad component(expected userinfo component or user component): #{v}" end @@ -291,7 +298,7 @@ module URI "password component depends user component" end - if @parser.regexp[:USERINFO] !~ v + if parser.regexp[:USERINFO] !~ v raise InvalidComponentError, "bad component(expected user component): #{v}" end @@ -356,7 +363,7 @@ module URI private :split_userinfo def escape_userpass(v) - v = @parser.escape(v, /[@:\/]/o) # RFC 1738 section 3.1 #/ + v = parser.escape(v, /[@:\/]/o) # RFC 1738 section 3.1 #/ end private :escape_userpass @@ -384,7 +391,7 @@ module URI if @registry || @opaque raise InvalidURIError, "can not set host with registry or opaque" - elsif @parser.regexp[:HOST] !~ v + elsif parser.regexp[:HOST] !~ v raise InvalidComponentError, "bad component(expected host component): #{v}" end @@ -410,7 +417,7 @@ module URI if @registry || @opaque raise InvalidURIError, "can not set port with registry or opaque" - elsif !v.kind_of?(Fixnum) && @parser.regexp[:PORT] !~ v + elsif !v.kind_of?(Fixnum) && parser.regexp[:PORT] !~ v raise InvalidComponentError, "bad component(expected port component): #{v}" end @@ -446,7 +453,7 @@ module URI if @host || @port || @user # userinfo = @user + ':' + @password raise InvalidURIError, "can not set registry with host, port, or userinfo" - elsif v && @parser.regexp[:REGISTRY] !~ v + elsif v && parser.regexp[:REGISTRY] !~ v raise InvalidComponentError, "bad component(expected registry component): #{v}" end @@ -476,12 +483,12 @@ module URI end if @scheme - if v && v != '' && @parser.regexp[:ABS_PATH] !~ v + if v && v != '' && parser.regexp[:ABS_PATH] !~ v raise InvalidComponentError, "bad component(expected absolute path component): #{v}" end else - if v && v != '' && @parser.regexp[:ABS_PATH] !~ v && @parser.regexp[:REL_PATH] !~ v + if v && v != '' && parser.regexp[:ABS_PATH] !~ v && parser.regexp[:REL_PATH] !~ v raise InvalidComponentError, "bad component(expected relative path component): #{v}" end @@ -513,7 +520,7 @@ module URI "query conflicts with opaque" end - if v && v != '' && @parser.regexp[:QUERY] !~ v + if v && v != '' && parser.regexp[:QUERY] !~ v raise InvalidComponentError, "bad component(expected query component): #{v}" end @@ -542,7 +549,7 @@ module URI if @host || @port || @user || @path # userinfo = @user + ':' + @password raise InvalidURIError, "can not set opaque with host, port, userinfo or path" - elsif v && @parser.regexp[:OPAQUE] !~ v + elsif v && parser.regexp[:OPAQUE] !~ v raise InvalidComponentError, "bad component(expected opaque component): #{v}" end @@ -565,7 +572,7 @@ module URI def check_fragment(v) return v unless v - if v && v != '' && @parser.regexp[:FRAGMENT] !~ v + if v && v != '' && parser.regexp[:FRAGMENT] !~ v raise InvalidComponentError, "bad component(expected fragment component): #{v}" end @@ -777,7 +784,7 @@ module URI case oth when Generic when String - oth = @parser.parse(oth) + oth = parser.parse(oth) else raise ArgumentError, "bad argument(expected URI object or URI string)" @@ -848,7 +855,7 @@ module URI case oth when Generic when String - oth = @parser.parse(oth) + oth = parser.parse(oth) else raise ArgumentError, "bad argument(expected URI object or URI string)" @@ -869,7 +876,7 @@ module URI rel = URI::Generic.new(nil, # it is relative URI self.userinfo, self.host, self.port, self.registry, self.path, self.opaque, - self.query, self.fragment, @parser) + self.query, self.fragment, parser) if rel.userinfo != oth.userinfo || rel.host.to_s.downcase != oth.host.to_s.downcase || @@ -960,7 +967,7 @@ module URI case oth when Generic when String - oth = @parser.parse(oth) + oth = parser.parse(oth) else raise ArgumentError, "bad argument(expected URI object or URI string)" @@ -1059,7 +1066,7 @@ module URI end def eql?(oth) - @parser == oth.parser && + parser == oth.parser && self.component_ary.eql?(oth.component_ary) end @@ -1117,7 +1124,7 @@ module URI def coerce(oth) case oth when String - oth = @parser.parse(oth) + oth = parser.parse(oth) else super end diff --git a/lib/uri/mailto.rb b/lib/uri/mailto.rb index 4fab6e23a5..240c849e9a 100644 --- a/lib/uri/mailto.rb +++ b/lib/uri/mailto.rb @@ -159,7 +159,7 @@ module URI return true unless v return true if v.size == 0 - if @parser.regexp[:OPAQUE] !~ v || /\A#{MAILBOX_PATTERN}*\z/o !~ v + if parser.regexp[:OPAQUE] !~ v || /\A#{MAILBOX_PATTERN}*\z/o !~ v raise InvalidComponentError, "bad component(expected opaque component): #{v}" end @@ -183,7 +183,7 @@ module URI return true unless v return true if v.size == 0 - if @parser.regexp[:OPAQUE] !~ v || + if parser.regexp[:OPAQUE] !~ v || /\A(#{HEADER_PATTERN}(?:\&#{HEADER_PATTERN})*)\z/o !~ v raise InvalidComponentError, "bad component(expected opaque component): #{v}" @@ -239,18 +239,18 @@ module URI # # => "To: ruby-list@ruby-lang.org\nSubject: subscribe\nCc: myaddr\n\n\n" # def to_mailtext - to = @parser.unescape(@to) + to = parser.unescape(@to) head = '' body = '' @headers.each do |x| case x[0] when 'body' - body = @parser.unescape(x[1]) + body = parser.unescape(x[1]) when 'to' - to << ', ' + @parser.unescape(x[1]) + to << ', ' + parser.unescape(x[1]) else - head << @parser.unescape(x[0]).capitalize + ': ' + - @parser.unescape(x[1]) + "\n" + head << parser.unescape(x[0]).capitalize + ': ' + + parser.unescape(x[1]) + "\n" end end |