Permalink
Browse files

Another fix for spaces in files

Based on the format of ls-tree:
<mode> SP <type> SP <object> TAB <file>
I modified the split logic to look for only one space, or a tab
character. Now it correctly handles files with leading spaces.
All other tests pass
  • Loading branch information...
1 parent ef2870b commit 6ca74ab937a5f8173dd32475f281418ce20ee6e7 David Kowis committed Apr 6, 2011
Showing with 11 additions and 2 deletions.
  1. +1 −1 lib/grit/tree.rb
  2. +10 −1 test/test_rgit_spaces.rb
View
@@ -65,7 +65,7 @@ def create_initialize(repo, atts)
#
# Returns Grit::Blob or Grit::Tree
def content_from_string(repo, text)
- mode, type, id, name = text.split(" ", 4)
+ mode, type, id, name = text.split(/ |\t/, 4)
case type
when "tree"
Tree.create(repo, :id => id, :mode => mode, :name => name)
View
@@ -38,6 +38,15 @@ def test_log_with_path_leading_space_in_a_branch
assert_equal "36a4f6bc8c5e4e67534b98c996f4e91ffff73ea5", log.first.to_s
end
-
+ def test_tree_with_leading_space
+ tree = @repo.tree()
+ names = tree.blobs.collect { |b| b.name }
+ assert names.include?(" an evil file with a leading space"), "does not contain the leading space named file"
+ end
+ def test_tree_with_trailing_space
+ tree = @repo.tree()
+ names = tree.blobs.collect { |b| b.name }
+ assert names.include?("an evil file with a trailing space "), "does not contain the trailing space named file"
+ end
end

0 comments on commit 6ca74ab

Please sign in to comment.