lineofflight / peddler

Amazon Selling Partner API (SP-API) in Ruby
https://lineofflight.github.io/peddler/
MIT License
307 stars 130 forks source link

Encoding issues #94

Closed alexfalkowski closed 7 years ago

alexfalkowski commented 7 years ago

Hi,

Thanks for the great library. We are using MWS::Reports::Client. When we

get_report('ID').body

I can see that text comes back as für

Though when we call

get_report('ID').parse.to_a

We get the text für

Seems to me something is using the wrong encoding. Maybe then CSV parsing is causing it?

hakanensari commented 7 years ago

Just to confirm, are you using the latest version?

alexfalkowski commented 7 years ago

From my Gemfile.lock peddler (1.6.1)

alexfalkowski commented 7 years ago
irb(main):020:0> body.encoding == 'UTF-8'
=> false
irb(main):021:0> body.encoding
=> #<Encoding:UTF-8>
irb(main):022:0> body.encoding == Encoding::UTF_8
=> true
alexfalkowski commented 7 years ago

So it looks like when I body.force_encoding(Encoding::UTF_8) the parsing works correctly.

alexfalkowski commented 7 years ago

So is it forcing the wrong encoding?

alexfalkowski commented 7 years ago

So this fixes is for me

module Peddler::FlatFileParserExtensions
  def scrub_body!(_)
    body.force_encoding(Encoding::UTF_8) unless body.encoding == Encoding::UTF_8
  end
end

class Peddler::FlatFileParser
  prepend Peddler::FlatFileParserExtensions
end
hakanensari commented 7 years ago

Thanks, @alexfalkowski. I pushed your fix to master.

alexfalkowski commented 7 years ago

Thank you!