Skip to content

Commit

Permalink
Another fix for spaces in files
Browse files Browse the repository at this point in the history
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
David Kowis committed Apr 6, 2011
1 parent ef2870b commit 6ca74ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/grit/tree.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def create_initialize(repo, atts)
# #
# Returns Grit::Blob or Grit::Tree # Returns Grit::Blob or Grit::Tree
def content_from_string(repo, text) def content_from_string(repo, text)
mode, type, id, name = text.split(" ", 4) mode, type, id, name = text.split(/ |\t/, 4)
case type case type
when "tree" when "tree"
Tree.create(repo, :id => id, :mode => mode, :name => name) Tree.create(repo, :id => id, :mode => mode, :name => name)
Expand Down
11 changes: 10 additions & 1 deletion test/test_rgit_spaces.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ def test_log_with_path_leading_space_in_a_branch
assert_equal "36a4f6bc8c5e4e67534b98c996f4e91ffff73ea5", log.first.to_s assert_equal "36a4f6bc8c5e4e67534b98c996f4e91ffff73ea5", log.first.to_s
end 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 end

0 comments on commit 6ca74ab

Please sign in to comment.