# Marshaling URI between 1.8 and 1.9

**URL:** <https://www.ruby-forum.com/t/marshaling-uri-between-1-8-and-1-9/167265>\
**Category:** Development\
**Created:** [May 6, 2009, 7:22am UTC](https://www.ruby-forum.com/t/marshaling-uri-between-1-8-and-1-9/167265 "2009-05-06T07:22:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tanaka\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@Tanaka\_A](https://www.ruby-forum.com/u/Tanaka_A)\
**Post date:** [May 6, 2009, 7:22am UTC](https://www.ruby-forum.com/t/marshaling-uri-between-1-8-and-1-9/167265/1 "2009-05-06T07:22:30Z")

</div>

e$B5$$,$D$$$?$s$G$9$,!"e(BURI e$B%\*%V%8%'%/%H$re(B marshal e$B$Ge(B 1.9  
e$B$+$ie(B  
1.8 e$B$K0$=$&$H$9$k$H\<:GT$7$^$9!#e(B

% ruby -v  
ruby 1.9.2dev (2009-05-02 trunk 23326) [i686-linux]  
% ruby-1.8 -v  
ruby 1.8.8dev (2009-04-22 revision 23257) [i686-linux]

% ruby -ruri -e ‘Marshal.dump(URI(“[http://example.org](http://example.org)”), STDOUT)’ \> u19  
% ruby-1.8 -ruri -e ‘Marshal.load(STDIN)’ \< u19  
-e:1:in `load’: undefined class/module URI::Parser (ArgumentError)  
from -e:1

e$BM}M3$O%(%i!\<%a%C%;!\<%8$K=q$$$F$"$kDL$j$G!"e(B1.9 e$B$Ne(B URI  
e$B%_%V%8%'e(B  
e$B%/%H$K$Oe(B URI::Parser e$B%_%V%8%'%/%H$,F~$C$F$$$k$N$K!"e(B1.8  
e$B$K$Oe(B  
URI::Parser e$B%/%i%9$,$J$$$+$i$G$9!#e(B

e$B5U$K!"e(B1.8 e$B$Ne(B URI e$B%\*%V%8%'%/%H$re(B 1.9  
e$B$K0$9$N$O!"e(BMashal.load  
e$B$^$G$OF0$-$^$9!#e(B

% ruby-1.8 -ruri -e ‘Marshal.dump(URI(“[http://example.org](http://example.org)”), STDOUT)’ \>  
u18  
% ruby -ruri -e ‘p Marshal.load(STDIN)’ \< u18  
#\<URI::HTTP:0xa072150 URL:[http://example.org](http://example.org)\>

e$B$G$b!"$=$l$K$J$K$+O"7k$7$?$j$9$k$H%(%i!\<$K$J$j$^$9!#e(B

% ruby -v -ruri -e ‘p Marshal.load(STDIN) + “foo”’ \< u18  
ruby 1.9.2dev (2009-05-02 trunk 23326) [i686-linux]  
/home/akr/ruby/yarvo0/lib/ruby/1.9.1/uri/generic.rb:780: warning:  
instance variable @parser not initialized  
/home/akr/ruby/yarvo0/lib/ruby/1.9.1/uri/generic.rb:737:in `rescue in merge': undefined method `parse’ for nil:NilClass (NoMethodError)  
from /home/akr/ruby/yarvo0/lib/ruby/1.9.1/uri/generic.rb:734:in  
`merge' from -e:1:in `’

e$B$3$NM}M3$Oe(B @parser e$B$,$J$$$+$i$G$9!#e(B

e$B$3$N%Q!\<%6$NM-L5$O!"e(Bmarshal e$B$7$?7k2L$N%5%$%:$K$b1F6A$7$F$$e(B  
e$B$F!"e(B1.9 e$B$G$Oe(B 20K e$B$[$IBg$-$/$J$C$F$$$^$9!#e(B

% ls -l u18 u19  
-rw-r–r-- 1 akr akr 131 2009-05-06 14:08 u18  
-rw-r–r-- 1 akr akr 21333 2009-05-06 14:08 u19

e$B;W$&$N$G$9$,!"%G%U%)%k%H$N%Q!\<%6$r;H$&$H$-$O%$%s%9%?%s%9JQ?te(B  
e$B$K$O5-O?$7$J$$$h$&$K$9$k$N$O$I$&$G$7$g$&$+!#e(B

e$B$=$&$9$l$P!"e(B(e$B%G%U%)%k%H$N%Q!\<%6$r;HMQ$9$ke(B URI e$B$G$Oe(B)  
e$B%Q!\<%6$,e(B  
marshal e$B$7$?%G!\<%?$KI=$l$J$/$J$k$N$G!"e(B1.8 e$B$He(B 1.9  
e$B$N4V$Ge(B  
marshal e$B$G$-$k$h$&$K$J$j$^$9!#e(B

# % svn diff --diff-cmd diff -x ‘-u -p’ Index: lib/uri/mailto.rb

— lib/uri/mailto.rb (revision 23350)  
+++ lib/uri/mailto.rb (working copy)  
@@ -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: removed\_email\_address@domain.invalid\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

```

# Index: lib/uri/generic.rb

— lib/uri/generic.rb (revision 23350)  
+++ lib/uri/generic.rb (working copy)  
@@ -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

- 

```
 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

```

---

<div class="post-metadata">

**Author:** ![Tanaka\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@Tanaka\_A](https://www.ruby-forum.com/u/Tanaka_A)\
**Post date:** [May 7, 2009, 7:42am UTC](https://www.ruby-forum.com/t/marshaling-uri-between-1-8-and-1-9/167265/2 "2009-05-07T07:42:19Z")

</div>

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:38377] Marshaling URI between 1.8 and 1.9”  
on Wed, 6 May 2009 14:21:34 +0900, Tanaka A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
writes:

|e$B5$$,$D$$$?$s$G$9$,!"e(BURI e$B%_%V%8%‘%/%H$re(B marshal e$B$Ge(B 1.9 e$B$+$ie(B  
|1.8 e$B$K0$=$&$H$9$k$H\<:GT$7$^$9!#e(B  
|  
|% ruby -v  
|ruby 1.9.2dev (2009-05-02 trunk 23326) [i686-linux]  
|% ruby-1.8 -v  
|ruby 1.8.8dev (2009-04-22 revision 23257) [i686-linux]  
|  
|% ruby -ruri -e ‘Marshal.dump(URI(“[http://example.org](http://example.org)”), STDOUT)’ \> u19  
|% ruby-1.8 -ruri -e ‘Marshal.load(STDIN)’ \< u19  
|-e:1:in `load’: undefined class/module URI::Parser (ArgumentError)  
| from -e:1  
|  
|e$BM}M3$O%(%i!\<%a%C%;!\<%8$K=q$$$F$"$kDL$j$G!"e(B1.9 e$B$Ne(B URI e$B%_%V%8%‘e(B  
|e$B%/%H$K$Oe(B URI::Parser e$B%_%V%8%'%/%H$,F~$C$F$$$k$N$K!"e(B1.8 e$B$K$Oe(B  
|URI::Parser e$B%/%i%9$,$J$$$+$i$G$9!#e(B  
|  
|e$B5U$K!"e(B1.8 e$B$Ne(B URI e$B%_%V%8%’%/%H$re(B 1.9 e$B$K0$9$N$O!"e(BMashal.load  
|e$B$^$G$OF0$-$^$9!#e(B

|e$B$3$NM}M3$Oe(B @parser e$B$,$J$$$+$i$G$9!#e(B

|e$B;W$&$N$G$9$,!"%G%U%)%k%H$N%Q!\<%6$r;H$&$H$-$O%$%s%9%?%s%9JQ?te(B  
|e$B$K$O5-O?$7$J$$$h$&$K$9$k$N$O$I$&$G$7$g$&$+!#e(B  
|  
|e$B$=$&$9$l$P!"e(B(e$B%G%U%)%k%H$N%Q!\<%6$r;HMQ$9$ke(B URI e$B$G$Oe(B) e$B%Q!\<%6$,e(B  
|marshal e$B$7$?%G!\<%?$KI=$l$J$/$J$k$N$G!"e(B1.8 e$B$He(B 1.9 e$B$N4V$Ge(B  
|marshal e$B$G$-$k$h$&$K$J$j$^$9!#e(B

e$B;d$O$3$NJQ99$K;?@.$G$9!#e(B

---

<div class="post-metadata">

**Author:** ![Tanaka\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@Tanaka\_A](https://www.ruby-forum.com/u/Tanaka_A)\
**Post date:** [May 27, 2009, 10:13am UTC](https://www.ruby-forum.com/t/marshaling-uri-between-1-8-and-1-9/167265/3 "2009-05-27T10:13:38Z")

</div>

(2009e$BG/e(B05e$B7ne(B07e$BF|e(B 14:41), Yukihiro M.  
e$B$5$s$O=q$-$^$7$?e(B:

> |-e:1:in `load’: undefined class/module URI::Parser (ArgumentError)
> 
> |e$B;W$&$N$G$9$,!"%G%U%)%k%H$N%Q!\<%6$r;H$&$H$-$O%$%s%9%?%s%9JQ?te(B  
> |e$B$K$O5-O?$7$J$$$h$&$K$9$k$N$O$I$&$G$7$g$&$+!#e(B  
> |  
> |e$B$=$&$9$l$P!"e(B(e$B%G%U%)%k%H$N%Q!\<%6$r;HMQ$9$ke(B URI e$B$G$Oe(B) e$B%Q!\<%6$,e(B  
> |marshal e$B$7$?%G!\<%?$KI=$l$J$/$J$k$N$G!"e(B1.8 e$B$He(B 1.9 e$B$N4V$Ge(B  
> |marshal e$B$G$-$k$h$&$K$J$j$^$9!#e(B
> 
> e$B;d$O$3$NJQ99$K;?@.$G$9!#e(B

akre$B$5$s!"e(Bcommite$B$\*4j$$$7$A$c$C$F$$$$$G$9$+e(B?
