OAuthClient::escape problem
Closed this issue · 4 comments
Hello,
flickraw cannot use Japanese, maybe after this change.
#39
/Users/xxxxx/.rvm/gems/ruby-1.8.7-p357/gems/flickraw-0.9.5/lib/flickraw/oauth.rb:151:in
post': signature_invalid (FlickRaw::OAuthClient::FailedResponse) from /Users/xxxxx/.rvm/gems/ruby-1.8.7-p357/gems/flickraw-0.9.5/lib/flickraw/oauth.rb:86:in
post_form'
from /Users/xxxxx/.rvm/gems/ruby-1.8.7-p357/gems/flickraw-0.9.5/lib/flickraw/api.rb:53:incall' from (eval):3:in
editMeta'
from /Users/xxxxx/Documents/Aptana Studio 3 Workspace/flickr/flickr.rb:97
from /Users/xxxxx/Documents/Aptana Studio 3 Workspace/flickr/flickr.rb:95:in `each'
from /Users/xxxxx/Documents/Aptana Studio 3 Workspace/flickr/flickr.rb:95
using this monkey patch, it's ok.
require "flickraw"
module FlickRaw
class OAuthClient
class << self
def escape(v); URI.escape(v.to_s, /[^a-zA-Z0-9\-\.\_\~]/) end
end
end
end
Thanks,
kinumi
Hello kinumi,
I believe this is an encoding bug. Can you try the commit 2133762 I just pushed and tell me if it works ?
Thanks,
Mael
Thanks,
I tried it, then...
ruby1.9.3 -> ok
ruby1.8.7 -> ng (and I want to use 1.8.7!)
Test Code:
("現像" is "\xE7\x8F\xBE\xE5\x83\x8F" in utf8)
#!ruby -Ku
require "rubygems"
require "uri"
require "./flickraw/lib/flickraw"
str = "現像"
puts "#{str} should be escaped to [#{URI.escape(str)}]"
puts "#{str} is escaped to [#{FlickRaw::OAuthClient.escape(str)}]"
Result:
$ rvm use 1.9.3
$ ruby -I ./flickraw/lib/ flickr.rb
現像 should be escaped to [%E7%8F%BE%E5%83%8F]
現像 is escaped to [%E7%8F%BE%E5%83%8F]
$ rvm use 1.8.7
$ ruby -I ./flickraw/lib/ flickr.rb
現像 should be escaped to [%E7%8F%BE%E5%83%8F]
現像 is escaped to [%E7%E5]
I modified oauth.rb. It seems to work well.
Before:
def escape(s)
encode_value(s).gsub(/[^a-zA-Z0-9\-\.\_\~]/) {
sprintf("%%%02X", $&.unpack("C")[0])
}
end
After:
def escape(s)
encode_value(s).gsub(/[^a-zA-Z0-9\-\.\_\~]/) {
$&.unpack("C*").map{|i| sprintf("%%%02X", i) }.join
}
end