Commit d4ef3be3 authored by Thong Kuah's avatar Thong Kuah

Frozen string cannot change encoding

This was shown in specs but surely this will be happening in application
code as well if this method is passes a frozen string.

We were also trying to force_encode a OmniAuth::AuthHash which had the
very confusing behaviour of returning nil when it was sent a method that
it did not define. Fix that by only force_encoding a String.
parent 595a092a
......@@ -60,8 +60,7 @@ module Gitlab
def get_info(key)
value = info[key]
Gitlab::Utils.force_utf8(value) if value
value
value.is_a?(String) ? Gitlab::Utils.force_utf8(value) : value
end
def username_and_email
......
......@@ -22,7 +22,7 @@ module Gitlab
end
def force_utf8(str)
str.force_encoding(Encoding::UTF_8)
str.dup.force_encoding(Encoding::UTF_8)
end
def ensure_utf8_size(str, bytes:)
......
......@@ -40,7 +40,11 @@ describe Gitlab::Auth::OAuth::AuthHash do
last_name: last_name_ascii,
name: name_ascii,
nickname: nickname_ascii,
uid: uid_ascii
uid: uid_ascii,
address: {
locality: 'some locality',
country: 'some country'
}
}
end
......@@ -51,6 +55,7 @@ describe Gitlab::Auth::OAuth::AuthHash do
it { expect(auth_hash.username).to eql nickname_utf8 }
it { expect(auth_hash.name).to eql name_utf8 }
it { expect(auth_hash.password).not_to be_empty }
it { expect(auth_hash.location).to eq 'some locality, some country' }
end
context 'email not provided' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment