chore: Persist emojis in Contact Import (#7803)

The previous fix would remove emojis in contact data. This change ensures they are persisited

ref: #7787
This commit is contained in:
Sojan Jose
2023-08-24 14:04:52 -07:00
committed by GitHub
parent 3dd3b7b3aa
commit 64ae9f625a
3 changed files with 20 additions and 1 deletions

View File

@@ -27,7 +27,11 @@ class DataImportJob < ApplicationJob
rejected_contacts = []
# Ensuring that importing non utf-8 characters will not throw error
data = @data_import.import_file.download
clean_data = data.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
utf8_data = data.force_encoding('UTF-8')
# Ensure that the data is valid UTF-8, preserving valid characters
clean_data = utf8_data.valid_encoding? ? utf8_data : utf8_data.encode('UTF-16le', invalid: :replace, replace: '').encode('UTF-8')
csv = CSV.parse(clean_data, headers: true)
csv.each do |row|