Browse Source

handle bulk upload files with boms (#1233)

pull/1237/head
Phil Lee 2 years ago committed by GitHub
parent
commit
1a5a64e18e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/services/bulk_upload/lettings/csv_parser.rb
  2. 17
      spec/services/bulk_upload/lettings/csv_parser_spec.rb

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

@ -50,7 +50,7 @@ private
def normalised_string
return @normalised_string if @normalised_string
@normalised_string = File.read(path)
@normalised_string = File.read(path, encoding: "bom|utf-8")
@normalised_string.gsub!("\r\n", "\n")
@normalised_string

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

@ -35,4 +35,21 @@ RSpec.describe BulkUpload::Lettings::CsvParser do
expect(service.row_parsers[0].field_12).to eql(log.age1)
end
end
context "when parsing with BOM aka byte order mark" do
let(:file) { Tempfile.new }
let(:path) { file.path }
let(:log) { build(:lettings_log, :completed) }
let(:bom) { "\uFEFF" }
before do
file.write(bom)
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

Loading…
Cancel
Save