diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-12-13 18:49:17 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-12-13 18:52:49 +0300 |
commit | 43af4e5577e5ea338ea5cf072cd0635e3dabcc9e (patch) | |
tree | 67764aab8d39c8109d09e12343b553feff1d45f0 /db/migrate/20161124141322_migrate_process_commit_worker_jobs.rb | |
parent | db9e1635d0d17596193ecbee8e0acc1916918d1d (diff) |
Encode when migrating ProcessCommitWorker jobs
If the source encoding is not UTF-8 we need to encode the data as
`JSON.dump` may throw an error if the input can not be converted to
UTF-8. We only encode when necessary to reduce the overhead.
Fixes gitlab-org/gitlab-ce#25489
Diffstat (limited to 'db/migrate/20161124141322_migrate_process_commit_worker_jobs.rb')
-rw-r--r-- | db/migrate/20161124141322_migrate_process_commit_worker_jobs.rb | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/db/migrate/20161124141322_migrate_process_commit_worker_jobs.rb b/db/migrate/20161124141322_migrate_process_commit_worker_jobs.rb index 453a44e271a..77e0c40d850 100644 --- a/db/migrate/20161124141322_migrate_process_commit_worker_jobs.rb +++ b/db/migrate/20161124141322_migrate_process_commit_worker_jobs.rb @@ -47,14 +47,14 @@ class MigrateProcessCommitWorkerJobs < ActiveRecord::Migration hash = { id: commit.oid, - message: commit.message, + message: encode(commit.message), parent_ids: commit.parent_ids, authored_date: commit.author[:time], - author_name: commit.author[:name], - author_email: commit.author[:email], + author_name: encode(commit.author[:name]), + author_email: encode(commit.author[:email]), committed_date: commit.committer[:time], - committer_email: commit.committer[:email], - committer_name: commit.committer[:name] + committer_email: encode(commit.committer[:email]), + committer_name: encode(commit.committer[:name]) } payload['args'][2] = hash @@ -89,4 +89,14 @@ class MigrateProcessCommitWorkerJobs < ActiveRecord::Migration end end end + + def encode(data) + encoding = Encoding::UTF_8 + + if data.encoding == encoding + data + else + data.encode(encoding, invalid: :replace, undef: :replace) + end + end end |