Skip to content

Commit 917bcd7

Browse files
committed
In ls-files do not unescape file paths with eval
Signed-off-by: James Couball <jcouball@yahoo.com>
1 parent 74b8e11 commit 917bcd7

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/git/lib.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,9 @@ def ls_files(location=nil)
488488
command_lines('ls-files', '--stage', location).each do |line|
489489
(info, file) = line.split("\t")
490490
(mode, sha, stage) = info.split
491-
file = eval(file) if file =~ /^\".*\"$/ # This takes care of quoted strings returned from git
491+
if file.start_with?('"') && file.end_with?('"')
492+
file = Git::EscapedPath.new(file[1..-2]).unescape
493+
end
492494
hsh[file] = {:path => file, :mode_index => mode, :sha_index => sha, :stage => stage}
493495
end
494496
hsh
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env ruby
2+
# encoding: utf-8
3+
4+
require File.dirname(__FILE__) + '/../test_helper'
5+
6+
# Test diff when the file path has to be quoted according to core.quotePath
7+
# See https://git-scm.com/docs/git-config#Documentation/git-config.txt-corequotePath
8+
#
9+
class TestLsFilesWithEscapedPath < Test::Unit::TestCase
10+
def test_diff_with_non_ascii_filename
11+
in_temp_dir do |path|
12+
create_file('my_other_file_☠', "First Line\n")
13+
create_file('my "text" file.txt', "First Line\n")
14+
create_file('README.md', '# My Project')
15+
`git init`
16+
`git add .`
17+
`git config --local core.safecrlf false` if Gem.win_platform?
18+
`git commit -m "First Commit"`
19+
update_file('my_other_file_☠', "Second Line\n")
20+
paths = Git.open('.').ls_files.keys.sort
21+
assert_equal(["my_other_file_☠", 'my "text" file.txt', 'README.md'].sort, paths)
22+
end
23+
end
24+
end

0 commit comments

Comments
 (0)