Browse Source

bulk upload handles invalid byte sequences (#1340)

- sometimes csv is not exported as utf8 therefore invalid byte sequences
  are removed
CLDC-1864-question-numbering-too
Phil Lee 2 years ago committed by GitHub
parent
commit
a12d26864b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/services/bulk_upload/lettings/csv_parser.rb
  2. 17
      spec/services/bulk_upload/lettings/csv_parser_spec.rb

1
app/services/bulk_upload/lettings/csv_parser.rb

@ -52,6 +52,7 @@ private
@normalised_string = File.read(path, encoding: "bom|utf-8") @normalised_string = File.read(path, encoding: "bom|utf-8")
@normalised_string.gsub!("\r\n", "\n") @normalised_string.gsub!("\r\n", "\n")
@normalised_string.scrub!("")
@normalised_string @normalised_string
end end

17
spec/services/bulk_upload/lettings/csv_parser_spec.rb

@ -52,4 +52,21 @@ RSpec.describe BulkUpload::Lettings::CsvParser do
expect(service.row_parsers[0].field_12).to eql(log.age1) expect(service.row_parsers[0].field_12).to eql(log.age1)
end end
end end
context "when an invalid byte sequence" do
let(:file) { Tempfile.new }
let(:path) { file.path }
let(:log) { build(:lettings_log, :completed) }
let(:invalid_sequence) { "\x81" }
before do
file.write(invalid_sequence)
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_csv_row)
file.close
end
it "parses csv correctly" do
expect(service.row_parsers[0].field_12).to eql(log.age1)
end
end
end end

Loading…
Cancel
Save