lineofflight / peddler

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

Mws Feeds response parsing breaks half away if feed response has blank lines. #113

Closed noorani786 closed 6 years ago

noorani786 commented 6 years ago

See attached file containing response from MWS. Parsing stops after 95 rows because of the extra newline characters.

FeedType submitted: _POST_FLAT_FILE_INVLOADERDATA

content = ..get_feed_submission_result(feed_id)
content.parse()

jacob_report.csv.zip

noorani786 commented 6 years ago

Given how unreliable feed responses have been, wondering if it is better to just read the file line-by-line and then pass it over to CSV.parse_line with begin..rescue?

noorani786 commented 6 years ago

Figured out the issue on this one. Here is the proposed fix:

peddler/flat_file_parser.rb

def extract_content_and_summary
      @content = body.encode('UTF-8', invalid: :replace, undef: :replace)
      parts = @content.split("\n\n") if @content.include?("\n\n")
      @summary = parts[0]
      @content = parts[1..parts.length-1].join()
 end
hakanensari commented 6 years ago

Thanks for reporting and explaining the bug, @noorani786. I'll push a fix to master.