Hi, I'm new to Ruby and new to using open-uri. But I think I found a
bug. Could someone take a look at this and if this is really a bug,
tell me who to report it to?
Thanks,
Todd.
Here's my little code snippet:
====== code starts ======
require 'open-uri'
string =
"http://www.infospace.com/home/redirect.htm?formfrom=qsearch&pgtarg=dire
ctory&wqhqn=2&qhqn="
string += "Bubba+Ray+Jackson&qc=Broomfield&qs=co"
puts "\nI'm going to try to open this: #{string}\n\n"
···
#
# This call throws a URI::InvalidURIError. Is that a bug?
# Looking at the error message, I THINK open_uri is following
# a redirection and somehow mis-parsing the new URI such that
# an erroneous space is inserted.
#
uri = open(string)
====== code ends ======
And here's the output:
I'm going to try to open this:
http://www.infospace.com/home/redirect.htm?formfrom=qsearch
&pgtarg=directory&wqhqn=2&qhqn=Bubba+Ray+Jackson&qc=Broomfield&qs=co
c:/ruby/lib/ruby/1.8/uri/common.rb:432:in `split': bad URI(is not URI?):
http://kevdb.info
space.com/home/white-pages/kevdb?kcfg=wpus&otmpl=%2Fwhite-pages%2Fresult
s.htm&qfm=n&qk=10&
top=1&qname=Bubba+Ray+Jackson&qf=Bubba&qn=Ray&qs=co&searchtype=citystate
&QN=Jackson&QF=Bub
ba Ray&qc=Broomfield (URI::InvalidURIError)
from c:/ruby/lib/ruby/1.8/uri/common.rb:481:in `parse'
from c:/ruby/lib/ruby/1.8/open-uri.rb:572:in `proxy_open'
from c:/ruby/lib/ruby/1.8/open-uri.rb:525:in `direct_open'
from c:/ruby/lib/ruby/1.8/open-uri.rb:169:in `open_loop'
from c:/ruby/lib/ruby/1.8/open-uri.rb:164:in `catch'
from c:/ruby/lib/ruby/1.8/open-uri.rb:164:in `open_loop'
from c:/ruby/lib/ruby/1.8/open-uri.rb:134:in `open_uri'
from c:/ruby/lib/ruby/1.8/open-uri.rb:424:in `open'
from c:/ruby/lib/ruby/1.8/open-uri.rb:85:in `open'
from open-uri-bug.rb:14
Bradley, Todd ha scritto:
it seem to work for me:
irb(main):001:0> require 'open-uri'
=> true
irb(main):002:0>
irb(main):003:0* string =
irb(main):004:0* "http://www.infospace.com/home/redirect.htm?formfrom=qsearch&pg
targ=dire
irb(main):005:0" ctory&wqhqn=2&qhqn="
=> "http://www.infospace.com/home/redirect.htm?formfrom=qsearch&pgtarg=dire\ncto
ry&wqhqn=2&qhqn="
irb(main):006:0> string += "Bubba+Ray+Jackson&qc=Broomfield&qs=co"
=> "http://www.infospace.com/home/redirect.htm?formfrom=qsearch&pgtarg=dire\ncto
ry&wqhqn=2&qhqn=Bubba+Ray+Jackson&qc=Broomfield&qs=co"
irb(main):007:0> open(string)
=> #<StringIO:0x2c2efd8>
In article <74297C5A6F930B4CB40D33BD127E882A0DA0E3@WSTEXCH00.westminster.polycom.com>,
"Bradley, Todd" <todd.bradley@Polycom.com> writes:
Hi, I'm new to Ruby and new to using open-uri. But I think I found a
bug. Could someone take a look at this and if this is really a bug,
tell me who to report it to?
It seems that the URI is redirected to invalid URI.
% ./ruby -ropen-uri -e '
class << URI
alias org_parse parse
def parse(arg)
p arg
org_parse(arg)
end
end
open("Infospace)
'
"Infospace;
"Infospace;
"http://kevdb.infospace.com/home/white-pages/kevdb?kcfg=wpus&otmpl=%2Fwhite-pages%2Fresults.htm&qfm=n&qk=10&top=1&qname=Bubba+Ray+Jackson&qf=Bubba&qn=Ray&qs=co&searchtype=citystate&QN=Jackson&QF=Bubba Ray&qc=Broomfield"
/home/akr/ruby/tmp-ruby/1.8/lib/ruby/1.8/uri/common.rb:432:in `split': bad URI(is not URI?): http://kevdb.infospace.com/home/white-pages/kevdb?kcfg=wpus&otmpl=%2Fwhite-pages%2Fresults.htm&qfm=n&qk=10&top=1&qname=Bubba+Ray+Jackson&qf=Bubba&qn=Ray&qs=co&searchtype=citystate&QN=Jackson&QF=Bubba Ray&qc=Broomfield (URI::InvalidURIError)
from /home/akr/ruby/tmp-ruby/1.8/lib/ruby/1.8/uri/common.rb:481:in `org_parse'
from -e:6:in `parse'
from /home/akr/ruby/tmp-ruby/1.8/lib/ruby/1.8/open-uri.rb:572:in `proxy_open'
from /home/akr/ruby/tmp-ruby/1.8/lib/ruby/1.8/open-uri.rb:525:in `direct_open'
from /home/akr/ruby/tmp-ruby/1.8/lib/ruby/1.8/open-uri.rb:169:in `open_loop'
from /home/akr/ruby/tmp-ruby/1.8/lib/ruby/1.8/open-uri.rb:164:in `catch'
from /home/akr/ruby/tmp-ruby/1.8/lib/ruby/1.8/open-uri.rb:164:in `open_loop'
from /home/akr/ruby/tmp-ruby/1.8/lib/ruby/1.8/open-uri.rb:134:in `open_uri'
from /home/akr/ruby/tmp-ruby/1.8/lib/ruby/1.8/open-uri.rb:424:in `open'
from /home/akr/ruby/tmp-ruby/1.8/lib/ruby/1.8/open-uri.rb:85:in `open'
from -e:9
Since the last URI
http://kevdb.infospace.com/home/white-pages/kevdb?kcfg=wpus&otmpl=%2Fwhite-pages%2Fresults.htm&qfm=n&qk=10&top=1&qname=Bubba+Ray+Jackson&qf=Bubba&qn=Ray&qs=co&searchtype=citystate&QN=Jackson&QF=Bubba Ray&qc=Broomfield
contains a space, URI.parse fails.
···
--
Tanaka Akira
I had this problem. My targeted web page is a bit snitty and insisted on
also receiving a user-agent.
myData = \
open('http://my.target.site&search=Find', \
"User-Agent" => "Ruby/#{RUBY_VERSION}" )
myData.each {|x| puts x + '\n'}
I hope this wasn't too late for you to use.
I had this problem. My targeted web page is a bit snitty and insisted on
also receiving a user-agent.
myData = \
open('http://my.target.site&search=Find', \
"User-Agent" => "Ruby/#{RUBY_VERSION}" )
myData.each {|x| puts x + '\n'}
I hope this wasn't too late for you to use.