Skip to content

Commit c4dd7b8

Browse files
JamedjoJames Edwards-Jones
authored and
James Edwards-Jones
committed
Prevent RevList failing on non utf8 paths
1 parent a52d8c1 commit c4dd7b8

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Prevent RevList failing on non utf8 paths
3+
merge_request: 16440
4+
author:
5+
type: fixed

lib/gitlab/git/rev_list.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def objects_from_output(object_output, require_path: nil)
9595
object_output.map do |output_line|
9696
sha, path = output_line.split(' ', 2)
9797

98-
next if require_path && path.blank?
98+
next if require_path && path.to_s.empty?
9999

100100
sha
101101
end.reject(&:nil?)

spec/lib/gitlab/git/rev_list_spec.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def stub_lazy_popen_rev_list(*additional_args, output:)
3939
]
4040

4141
expect(rev_list).to receive(:popen).with(*params) do |*_, lazy_block:|
42-
lazy_block.call(output.split("\n").lazy)
42+
lazy_block.call(output.lines.lazy.map(&:chomp))
4343
end
4444
end
4545

@@ -64,6 +64,15 @@ def stub_lazy_popen_rev_list(*additional_args, output:)
6464
expect(rev_list.new_objects(require_path: true)).to eq(%w[sha2])
6565
end
6666

67+
it 'can handle non utf-8 paths' do
68+
non_utf_char = [0x89].pack("c*").force_encoding("UTF-8")
69+
stub_lazy_popen_rev_list('newrev', '--not', '--all', '--objects', output: "sha2 πå†h/†ø/ƒîlé#{non_utf_char}\nsha1")
70+
71+
rev_list.new_objects(require_path: true) do |object_ids|
72+
expect(object_ids.force).to eq(%w[sha2])
73+
end
74+
end
75+
6776
it 'can yield a lazy enumerator' do
6877
stub_lazy_popen_rev_list('newrev', '--not', '--all', '--objects', output: "sha1\nsha2")
6978

0 commit comments

Comments
 (0)