Merge branch 'jej/lfs-rev-list-handles-non-utf-paths-41627' into 'master'

Prevent RevList failing on non utf8 paths

Closes #41627

See merge request gitlab-org/gitlab-ce!16440
This commit is contained in:
Stan Hu 2018-01-16 20:47:17 +00:00
commit 3228ac06a0
3 changed files with 16 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
title: Prevent RevList failing on non utf8 paths
merge_request: 16440
author:
type: fixed

View file

@ -95,7 +95,7 @@ module Gitlab
object_output.map do |output_line| object_output.map do |output_line|
sha, path = output_line.split(' ', 2) sha, path = output_line.split(' ', 2)
next if require_path && path.blank? next if require_path && path.to_s.empty?
sha sha
end.reject(&:nil?) end.reject(&:nil?)

View file

@ -39,7 +39,7 @@ describe Gitlab::Git::RevList do
] ]
expect(rev_list).to receive(:popen).with(*params) do |*_, lazy_block:| expect(rev_list).to receive(:popen).with(*params) do |*_, lazy_block:|
lazy_block.call(output.split("\n").lazy) lazy_block.call(output.lines.lazy.map(&:chomp))
end end
end end
@ -64,6 +64,15 @@ describe Gitlab::Git::RevList do
expect(rev_list.new_objects(require_path: true)).to eq(%w[sha2]) expect(rev_list.new_objects(require_path: true)).to eq(%w[sha2])
end end
it 'can handle non utf-8 paths' do
non_utf_char = [0x89].pack("c*").force_encoding("UTF-8")
stub_lazy_popen_rev_list('newrev', '--not', '--all', '--objects', output: "sha2 πå†h/†ø/ƒîlé#{non_utf_char}\nsha1")
rev_list.new_objects(require_path: true) do |object_ids|
expect(object_ids.force).to eq(%w[sha2])
end
end
it 'can yield a lazy enumerator' do it 'can yield a lazy enumerator' do
stub_lazy_popen_rev_list('newrev', '--not', '--all', '--objects', output: "sha1\nsha2") stub_lazy_popen_rev_list('newrev', '--not', '--all', '--objects', output: "sha1\nsha2")