Skip to content

Commit

Permalink
Added support for filenames which are quoted (usually containing inte…
Browse files Browse the repository at this point in the history
…rnational/unicode characters).
  • Loading branch information
gf3 committed Mar 17, 2009
1 parent 96bf1ac commit ee90922
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/git/lib.rb
Expand Up @@ -298,6 +298,7 @@ def ls_files
command_lines('ls-files', '--stage').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
hsh[file] = {:path => file, :mode_index => mode, :sha_index => sha, :stage => stage}
end
hsh
Expand Down
2 changes: 1 addition & 1 deletion lib/git/status.rb
Expand Up @@ -89,7 +89,7 @@ def construct_status
@files[file] = {:path => file, :untracked => true} unless @files[file] || File.directory?(file) || ignore.include?(file)
end
end

# find modified in tree
@base.lib.diff_files.each do |path, data|
@files[path] ? @files[path].merge!(data) : @files[path] = data
Expand Down

5 comments on commit ee90922

@minad
Copy link

@minad minad commented on ee90922 Mar 17, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eval is evil. This is the wrong way to do this

@minad
Copy link

@minad minad commented on ee90922 Mar 17, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eval is the wrong way to do this. That introduces security problems. Why not simply remove the first and last character?

@gf3
Copy link
Contributor Author

@gf3 gf3 commented on ee90922 Mar 17, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, the reason I added the eval is because git returns a slash encoded string whereas Dir.glob, it appears, deals directly with the international characters, and that will fail during the comparison for finding untracked files. E.g.
<pre>

> > “Euge\314\201nie Eckler.jpg” == “Eugénie Eckler.jpg”
> > => false
> >

 

@minad
Copy link

@minad minad commented on ee90922 Mar 17, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm ok. I just tested it, eval seems to be no problem because git properly escapes quotes etc. But using eval to remove escape sequences just does not feel right. Maybe there’s a better way to do it.

@gf3
Copy link
Contributor Author

@gf3 gf3 commented on ee90922 Mar 17, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it isn’t ideal. Perhaps we could escape the filenames that Dir.glob returns?

Please sign in to comment.