From d6066870cc38acde9a3608041e133ca64b6694c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20Carlb=C3=A4cker?= Date: Thu, 2 Nov 2017 08:29:03 +0000 Subject: [PATCH] Fix encoding issue with Repository.ls_files --- lib/gitlab/gitaly_client/commit_service.rb | 2 +- spec/lib/gitlab/git/repository_spec.rb | 5 +++++ .../88/3e379fcaa5f818fca81cdbabd7a497794d6535 | Bin 0 -> 304 bytes .../c8/b1ab16c858c67b680eea4644cf652485f555cf | Bin 0 -> 597 bytes .../e3/7697aea12699f0b44544332a7c0f41ace5fb16 | 2 ++ .../eb/a0c153ed20d927bab00507f356043b6b4be31e | Bin 0 -> 185 bytes .../f6/5ad228d96e2a2ae7088e8557fe8906f6dd2b3f | Bin 0 -> 642 bytes 7 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 spec/support/gitlab-git-test.git/objects/88/3e379fcaa5f818fca81cdbabd7a497794d6535 create mode 100644 spec/support/gitlab-git-test.git/objects/c8/b1ab16c858c67b680eea4644cf652485f555cf create mode 100644 spec/support/gitlab-git-test.git/objects/e3/7697aea12699f0b44544332a7c0f41ace5fb16 create mode 100644 spec/support/gitlab-git-test.git/objects/eb/a0c153ed20d927bab00507f356043b6b4be31e create mode 100644 spec/support/gitlab-git-test.git/objects/f6/5ad228d96e2a2ae7088e8557fe8906f6dd2b3f diff --git a/lib/gitlab/gitaly_client/commit_service.rb b/lib/gitlab/gitaly_client/commit_service.rb index a2b50f2507e..da5505cb2fe 100644 --- a/lib/gitlab/gitaly_client/commit_service.rb +++ b/lib/gitlab/gitaly_client/commit_service.rb @@ -18,7 +18,7 @@ module Gitlab response = GitalyClient.call(@repository.storage, :commit_service, :list_files, request) response.flat_map do |msg| - msg.paths.map { |d| d.dup.force_encoding(Encoding::UTF_8) } + msg.paths.map { |d| EncodingHelper.encode!(d.dup) } end end diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 0fa88d17f5d..75ff45ec379 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -1163,6 +1163,7 @@ describe Gitlab::Git::Repository, seed_helper: true do describe "#ls_files" do let(:master_file_paths) { repository.ls_files("master") } + let(:utf8_file_paths) { repository.ls_files("ls-files-utf8") } let(:not_existed_branch) { repository.ls_files("not_existed_branch") } it "read every file paths of master branch" do @@ -1184,6 +1185,10 @@ describe Gitlab::Git::Repository, seed_helper: true do it "returns empty array when not existed branch" do expect(not_existed_branch.length).to equal(0) end + + it "returns valid utf-8 data" do + expect(utf8_file_paths.map { |file| file.force_encoding('utf-8') }).to all(be_valid_encoding) + end end describe "#copy_gitattributes" do diff --git a/spec/support/gitlab-git-test.git/objects/88/3e379fcaa5f818fca81cdbabd7a497794d6535 b/spec/support/gitlab-git-test.git/objects/88/3e379fcaa5f818fca81cdbabd7a497794d6535 new file mode 100644 index 0000000000000000000000000000000000000000..1c47f34b9a5592530770a95b8e26029badb47851 GIT binary patch literal 304 zcmV-00nh$;0V^p=O;s>9uwXDWFfcPQQP8l^ypxn#q!5spnOBmOn3JPdoLs^1Z0@7k zn=W2+_U_hPR~~ia(376vi6#a>ppaUTnp|3vn3R)R%y8vT|3S<5lP~+6ES4~wP#P3v zeuWL9Dx)MfhhgE1AJ<*av_D>{(j0NqRD1i+1?zS}q%(69(}DUYgbQnXu&R{5THUbv z(32^Pv?}fIK@?;aGgJf%h-ZFw5?8%@M8xvYSvP^lRW~7$IcdcVEJqqYUJ{!m`O)Q( zIZ0V^p=O;s>6HD@q1FfcPQQP4}zEXhpI%P&f0xWCGN`YGc&1yQdVYvyu4 z&%G;urU^+^ZhlH>PHHj3-J08<_jmDU{@5JB@lGRRuS$-)7F3zDhohgntB=1s!*R#b z^%un}WcJK3OEI3sA2~aEvmZ>6zh6j@r&DN%r=PoCZVJP}inj2bkuw&3EMM{?H)9#U zR)b(YRH=JvZdztes$NxQ0Yl&3lt^>A^o?e*#u^>U{c?_<&g(#x`FJ|J`USf(Y+iLa zY_opfY|#SIo|n@&ibc7Po`ov$b@cQLarJZbb9M#UIrZj;rO$V>`pvyOJ+yPj{bQYv z_&T5}1A_dWU4w%`s`i%_s2<@-diH92hp+qXg!SFUjG%DB*FsOpL{Qgd<` zD)+p4HfL)oZ)*A`<;cpJ`&Y_r-U+cUFSWQNHHD$#fttNq)6Q literal 0 HcmV?d00001 diff --git a/spec/support/gitlab-git-test.git/objects/e3/7697aea12699f0b44544332a7c0f41ace5fb16 b/spec/support/gitlab-git-test.git/objects/e3/7697aea12699f0b44544332a7c0f41ace5fb16 new file mode 100644 index 00000000000..3be244dbda4 --- /dev/null +++ b/spec/support/gitlab-git-test.git/objects/e3/7697aea12699f0b44544332a7c0f41ace5fb16 @@ -0,0 +1,2 @@ +xK +0EgNI|ADt*^ mZ qGčY8ZK7"Fc%oHD9rZLsMJ2=ACmeFgVxI9H2XJrp6;N8z??>+zWƏBÞ f}bN@K\SY iSC \ No newline at end of file diff --git a/spec/support/gitlab-git-test.git/objects/eb/a0c153ed20d927bab00507f356043b6b4be31e b/spec/support/gitlab-git-test.git/objects/eb/a0c153ed20d927bab00507f356043b6b4be31e new file mode 100644 index 0000000000000000000000000000000000000000..2bf27fe50484b8d1a97340729fb4f05b1b53ef94 GIT binary patch literal 185 zcmV;q07n0K0iBLPYQr!PMZ4B1hHL{tvS(xoN-4=Qrx;B}sc>W$q1-4p$;IkGPmtw* z@E=dsT1$t4;zw_)AR#$U&P$*meo8)ARYs2}+0%f5G7(8Ozua``fC-}uOw*7#_#CIn zDJ4dm(*=V%O?K2lyy1KQSsR>7h28Od+QEt2Ej=GHYlF|Z)PuYLzxMaFa=9I3tzY2C nM)YxX1bgeOH5=WE`}TU*MKu1qOlrzA=pyT-ELZafWgk-vk#Jb0 literal 0 HcmV?d00001 diff --git a/spec/support/gitlab-git-test.git/objects/f6/5ad228d96e2a2ae7088e8557fe8906f6dd2b3f b/spec/support/gitlab-git-test.git/objects/f6/5ad228d96e2a2ae7088e8557fe8906f6dd2b3f new file mode 100644 index 0000000000000000000000000000000000000000..8ab8606c6be3aa3305d6ab06b9b9846a4cecaf17 GIT binary patch literal 642 zcmV-|0)72>0V^p=O;s>AFk>(@FfcPQQP8l^ypxn#q!5spnOBmOn3JPdoLs^1Z0@7k zn=W2+_U_hPR~~ia(376viBJuC>6s;&>3R7@sSNj5*-t-ZT&E!FHDk?O?&rC8<&enBRJk^MC?_`ao2(>bM|obb9eRecV{^6Si1hAc!kWK z8D=TQv-l%tM{o9nDf0IV3G#Fb4e|7I*UL>|I9SmZzB6*hqL1ZEe&l8>~FZ(EKA$dG=dG0<=sHz}WM;BkPQNPwpc70x)yWeq|NLqo- z!7DY17XqP*!d!!bJ^lR{X123$Q9LpG=3+Ku