Bug #5840
closedURI::MailTo.build - 2 of 3 examples fail on 1.9.2/1.93
Description
The array examples of URI::MailTo.build in the documentation fail on 1.9
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/uri/rdoc/URI/MailTo.html
ex
ruby-1.9.3-preview1 :003 > m2 = URI::MailTo.build(['john@example.com', [['Subject', 'Ruby'], ['Cc', 'jack@example.com']]])
URI::InvalidComponentError: bad component(expected opaque component): john@example.com?Subject=["Ruby"]&Cc=["jack@example.com"]
from /Users/primerano/Developer/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/1.9.1/uri/generic.rb:957:in check_opaque' from /Users/primerano/Developer/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/1.9.1/uri/generic.rb:988:in
opaque='
from /Users/primerano/Developer/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/1.9.1/uri/generic.rb:198:in initialize' from /Users/primerano/Developer/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/1.9.1/uri/mailto.rb:135:in
initialize'
from /Users/primerano/Developer/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/1.9.1/uri/generic.rb:140:in new' from /Users/primerano/Developer/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/1.9.1/uri/generic.rb:140:in
build'
from /Users/primerano/Developer/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/1.9.1/uri/mailto.rb:122:in build' from (irb):3 from /Users/primerano/Developer/.rvm/rubies/ruby-1.9.3-preview1/bin/irb:16:in
'
ruby-1.9.3-preview1 :004 > m3 = URI::MailTo.build({:to => 'listman@example.com', :headers => [['subject', 'subscribe']]})
URI::InvalidComponentError: bad component(expected opaque component): listman@example.com?subject=["subscribe"]
from /Users/primerano/Developer/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/1.9.1/uri/generic.rb:957:in check_opaque' from /Users/primerano/Developer/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/1.9.1/uri/generic.rb:988:in
opaque='
from /Users/primerano/Developer/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/1.9.1/uri/generic.rb:198:in initialize' from /Users/primerano/Developer/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/1.9.1/uri/mailto.rb:135:in
initialize'
from /Users/primerano/Developer/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/1.9.1/uri/generic.rb:140:in new' from /Users/primerano/Developer/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/1.9.1/uri/generic.rb:140:in
build'
from /Users/primerano/Developer/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/1.9.1/uri/mailto.rb:122:in build' from (irb):4 from /Users/primerano/Developer/.rvm/rubies/ruby-1.9.3-preview1/bin/irb:16:in
'
1st example works fine.
ruby-1.9.3-preview1 :005 > m1 = URI::MailTo.build(['joe@example.com', 'subject=Ruby'])
=> #<URI::MailTo:0x007fb75a025918 URL:mailto:joe@example.com?subject=Ruby>
Updated by primerano (Tony Primerano) almost 13 years ago
looking at the code it appears the header items should be a hash instead of an array. It makes for a nicer read
m3 = URI::MailTo.build({:to => 'listman@example.com', :headers => {'subject' => 'subscribe', 'body' => 'welcome'}})
=> #<URI::MailTo:0x007fd1632a4c48 URL:mailto:listman@example.com?subject=subscribe&body=welcome>
Hoping the docs will be updated instead of the code as I prefer this syntax.
Updated by naruse (Yui NARUSE) almost 13 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r34360.
Tony, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- lib/uri/mailto.rb (URI::MailTo.build): follow Array#to_s change of
Ruby 1.9; use Array#join. [Bug #5840]