Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In ls-files do not unescape file paths with eval #602

Merged
merged 1 commit into from Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/git/lib.rb
Expand Up @@ -488,7 +488,9 @@ def ls_files(location=nil)
command_lines('ls-files', '--stage', location).each do |line|
(info, file) = line.split("\t")
(mode, sha, stage) = info.split
file = eval(file) if file =~ /^\".*\"$/ # This takes care of quoted strings returned from git
if file.start_with?('"') && file.end_with?('"')
file = Git::EscapedPath.new(file[1..-2]).unescape
end
hsh[file] = {:path => file, :mode_index => mode, :sha_index => sha, :stage => stage}
end
hsh
Expand Down
22 changes: 22 additions & 0 deletions tests/units/test_ls_files_with_escaped_path.rb
@@ -0,0 +1,22 @@
#!/usr/bin/env ruby
# encoding: utf-8

require File.dirname(__FILE__) + '/../test_helper'

# Test diff when the file path has to be quoted according to core.quotePath
# See https://git-scm.com/docs/git-config#Documentation/git-config.txt-corequotePath
#
class TestLsFilesWithEscapedPath < Test::Unit::TestCase
def test_diff_with_non_ascii_filename
in_temp_dir do |path|
create_file('my_other_file_☠', "First Line\n")
create_file('README.md', '# My Project')
`git init`
`git add .`
`git config --local core.safecrlf false` if Gem.win_platform?
`git commit -m "First Commit"`
paths = Git.open('.').ls_files.keys.sort
assert_equal(["my_other_file_☠", 'README.md'].sort, paths)
end
end
end