Permalink
Browse files

strip newlines from tree entry names

ported from github.com
  • Loading branch information...
1 parent 4cdb531 commit 89e86f4bd6ad8854a0bb7a43813c8fc9baa0def8 @vmg vmg committed with sbryant Jul 3, 2012
Showing with 6 additions and 1 deletion.
  1. +6 −1 lib/grit/git-ruby/git_object.rb
@@ -125,6 +125,11 @@ def initialize(mode, filename, sha1o)
end
end
+ # Filenames can have weird characters that throw grit's text parsing
+ def safe_name
+ name.gsub(/[\r\n\0]/, '')
+ end
+
def type
case @mode & S_IFMT
when S_IFGITLINK
@@ -223,7 +228,7 @@ def type
def raw_content
# TODO: sort correctly
#@entry.sort { |a,b| a.name <=> b.name }.
- @entry.collect { |e| [[e.format_mode, e.format_type, e.sha1].join(' '), e.name].join("\t") }.join("\n")
+ @entry.collect { |e| [[e.format_mode, e.format_type, e.sha1].join(' '), e.safe_name].join("\t") }.join("\n")
end
def actual_raw

0 comments on commit 89e86f4

Please sign in to comment.