55502f40dc8b7c769880b10874abc9d0

trying to use URI to parse a big fat google chart api url...

URI.parse("http://chart.apis.google.com/chart?cht=lc&chs=200x30&chd=t:-1,53.9,53.9,40.0,38.6,34.3,32.5,31.0,30.1,26.7,24.8,23.1,21.7,11.5,10.9,10.1,5.7,3.7,2.1,0.0,9.5,100.0,98.3,95.8,91.8,85.0,83.8,81.8,66.5,59.7,56.7,53.9,52.1,35.3,33.9,33.4,28.7,27.3,23.6,20.7,18.5,16.1&chco=336699&chls=2,1,0&chm=o,990000,0,1,4|o,990000,0,41,4&chxt=r,x,y&chxs=0,990000,11,0,_|1,990000,1,0,_|2,990000,1,0,_&chxl=0:|$-2940.39|1:||2:||&chxp=0,16.1")

returns

        from /usr/lib/ruby/1.8/uri/common.rb:436:in `split'
        from /usr/lib/ruby/1.8/uri/common.rb:485:in `parse'
        from (irb):2

Refactorings

No refactoring yet !

4d72203c38dd5f3e3d2d446b5888e8a7

Elij

December 20, 2007, December 20, 2007 08:18, permalink

No rating. Login to rate!

It doesn't include the pipe character so the regular expression (to determine ABS or REL URI) is failing -- might be worth submitting a patch upstream if I'm right.

grep -n UNRESERVED /usr/lib/ruby/1.8/uri/common.rb
E13c31390e0369fcd5972292ce0e7b92

John Nunemaker

January 5, 2008, January 05, 2008 05:26, permalink

1 rating. Login to rate!

Escape the uri before parsing it. | is not safe but it's escaped version will work fine. Check out the irb code below:

>> require 'uri'
=> true
>> URI.escape('|')  
=> "%7C"
>> domain = "http://chart.apis.google.com/chart?cht=lc&chs=200x30&chd=t:-1,53.9,53.9,40.0,38.6,34.3,32.5,31.0,30.1,26.7,24.8,23.1,21.7,11.5,10.9,10.1,5.7,3.7,2.1,0.0,9.5,100.0,98.3,95.8,91.8,85.0,83.8,81.8,66.5,59.7,56.7,53.9,52.1,35.3,33.9,33.4,28.7,27.3,23.6,20.7,18.5,16.1&chco=336699&chls=2,1,0&chm=o,990000,0,1,4|o,990000,0,41,4&chxt=r,x,y&chxs=0,990000,11,0,_|1,990000,1,0,_|2,990000,1,0,_&chxl=0:|$-2940.39|1:||2:||&chxp=0,16.1"
=> "http://chart.apis.google.com/chart?cht=lc&chs=200x30&chd=t:-1,53.9,53.9,40.0,38.6,34.3,32.5,31.0,30.1,26.7,24.8,23.1,21.7,11.5,10.9,10.1,5.7,3.7,2.1,0.0,9.5,100.0,98.3,95.8,91.8,85.0,83.8,81.8,66.5,59.7,56.7,53.9,52.1,35.3,33.9,33.4,28.7,27.3,23.6,20.7,18.5,16.1&chco=336699&chls=2,1,0&chm=o,990000,0,1,4|o,990000,0,41,4&chxt=r,x,y&chxs=0,990000,11,0,_|1,990000,1,0,_|2,990000,1,0,_&chxl=0:|$-2940.39|1:||2:||&chxp=0,16.1"
>> URI.parse(URI.escape(domain))
=> #<URI::HTTP:0x1d67e4 URL:http://chart.apis.google.com/chart?cht=lc&chs=200x30&chd=t:-1,53.9,53.9,40.0,38.6,34.3,32.5,31.0,30.1,26.7,24.8,23.1,21.7,11.5,10.9,10.1,5.7,3.7,2.1,0.0,9.5,100.0,98.3,95.8,91.8,85.0,83.8,81.8,66.5,59.7,56.7,53.9,52.1,35.3,33.9,33.4,28.7,27.3,23.6,20.7,18.5,16.1&chco=336699&chls=2,1,0&chm=o,990000,0,1,4%7Co,990000,0,41,4&chxt=r,x,y&chxs=0,990000,11,0,_%7C1,990000,1,0,_%7C2,990000,1,0,_&chxl=0:%7C$-2940.39%7C1:%7C%7C2:%7C%7C&chxp=0,16.1>

Your refactoring





Format Copy from initial code

or Cancel