googlecharts gem URI::InvalidURIError fixed
Yesterday i was wondering who is right about the URI and as it turns out the culprit is the googlecharts gem. The RFC defines ‘UNWISE’ characters, the ruby URI implementation seem to correctly fail on them and the Google API defines the just the URI, not how it has to be encoded/escaped.
I posted the scary URI regex from the ruby open-uri package which fails to grasp the Google Charts URIs. Debugging such thing is no fun so i went for a quick fix instead and actually could find it in the googlecharts gem. Just replace:
jstize(@@url + query_params.join('&')) from ...ruby/gems/1.8/gems/googlecharts-0.2.0/lib/gchart.rb with:
unwise = []#%w({ } | \ ^ [ ] `)
query_params.each do |p|
unwise.each { |c| p.gsub!(c, "%#{c[0].to_s(16).upcase}") }
end
jstize(@@url + query_params.join('&'))this escapes the ‘|’ (pipe) characters which were causing the exception, like this one:
/opt/local/lib/ruby/1.8/uri/common.rb:436:in `split': bad URI(is not URI?): http://chart.apis.google.com/chart?chdl=requests(cached)|requests&chd=s:Fb9JJfgZ,Fb9KJfgq&cht=lc&chs=300x200 (URI::InvalidURIError)
Technorati Tags: ruby, googlecharts, google, gem, fix
Trackbacks
Use this link to trackback from your own site.
[...] a simple fix/hack for the googlecharts gemUhh!, this for sure is one of the more scary regular expressions you normally encounter. Its [...]
Many thanks! This did the job
Googlecharts 1.0.0 fixes this problem. Thanks Crux for your blogpost. Too bad I didn’t see it earlier. I just released an update of my gem fixing the problem you mentioned. The bug fix is based on your recommendation.
-Matt
[...] Aimonetti released a 1.0.0 version of his googlecharts gem which includes my URI bugfix i blogged about earlier. Me haven’t had so many opensource contributions yet, feels good though.Technorati Tags: [...]
Also consider using URI.escape(url), see http://www.ruby-doc.org/core/classes/URI/Escape.html