flexera-public / right_aws

RightScale Amazon Web Services Ruby Gems
MIT License
451 stars 175 forks source link

right_aws conflicts with Net::HTTP body containing special characters #101

Open zpasal opened 12 years ago

zpasal commented 12 years ago

Hi

not sure is this conflict produced by right_aws gem but following scenario is happening:

My localhost server doesn't got proper request. It gets: "Zaharije Pa\xC5\xA1ali" instead of "Zaharije Pa\xC5\xA1ali\xC4\x87" It seems that length of body isn't calculated correctly if body have special chars (Without special chars, length is correct).

But when i remove right_aws gem, it works fine.

Same bug can be reproduced without httparty but using plain Net::HTTP.

NOT WORKING

require "rubygems" require "net/http" require "right_aws" uri = URI.parse('http://localhost:3000') http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Post.new(uri.request_uri) req.body = File.open('test.txt', 'r:utf-8').read http.request req

WORKING CASE WITH NET::HTTP

require "rubygems" require "net/http" uri = URI.parse('http://localhost:3000') http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Post.new(uri.request_uri) req.body = File.open('test.txt', 'r:utf-8').read http.request req

Versions: OS: MAC OS Snow Leopard ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.6.0] right_aws (3.0.0)

best

molfar commented 12 years ago

Yes, I also have this problem.

zpasal commented 12 years ago

Currently my workaround for this is to normalize filenames e.g. replace all nonAlpha an nonNumber to '_'. We are doing this from flash but you can easily convert that to ruby:

private function normalizeFilename(file:FileReference):String { return file.name.replace(/^.*(|\/)/gi, '').replace(/[^A-Za-z0-9.-]/gi, '_'); }