summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/encoding_helper_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/encoding_helper_spec.rb')
-rw-r--r--spec/lib/gitlab/encoding_helper_spec.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/lib/gitlab/encoding_helper_spec.rb b/spec/lib/gitlab/encoding_helper_spec.rb
index b0c67cdafe1..690396d4dbc 100644
--- a/spec/lib/gitlab/encoding_helper_spec.rb
+++ b/spec/lib/gitlab/encoding_helper_spec.rb
@@ -98,6 +98,36 @@ RSpec.describe Gitlab::EncodingHelper do
end
end
+ describe '#encode_utf8_with_escaping!' do
+ where(:input, :expected) do
+ "abcd" | "abcd"
+ "DzDzDz" | "DzDzDz"
+ "\xC7\xB2\xC7DzDzDz" | "Dz%C7DzDzDz"
+ "🐤🐤🐤🐤\xF0\x9F\x90" | "🐤🐤🐤🐤%F0%9F%90"
+ "\xD0\x9F\xD1\x80 \x90" | "Пр %90"
+ "\x41" | "A"
+ end
+
+ with_them do
+ it 'escapes invalid UTF-8' do
+ expect(ext_class.encode_utf8_with_escaping!(input.dup.force_encoding(Encoding::ASCII_8BIT))).to eq(expected)
+ expect(ext_class.encode_utf8_with_escaping!(input)).to eq(expected)
+ end
+ end
+
+ context 'when feature flag is disabled' do
+ before do
+ stub_feature_flags(escape_gitaly_refs: false)
+ end
+
+ it 'uses #encode! method' do
+ expect(ext_class).to receive(:encode!).with('String')
+
+ ext_class.encode_utf8_with_escaping!('String')
+ end
+ end
+ end
+
describe '#encode_utf8' do
[
["nil", nil, nil],