diff options
author | Jason Petersen <jpetersen@bluekai.com> | 2013-09-10 16:02:44 -0600 |
---|---|---|
committer | Jason Petersen <jpetersen@bluekai.com> | 2013-09-12 16:23:11 -0600 |
commit | a3fa04e90133ca42efc7d8dc6cdb16b231b1f964 (patch) | |
tree | 73b20a40664360c8115fa187967beee1249b8b2b /spec | |
parent | cf0677de4b4b298e1459cf83c68ce7ea68e2aab7 (diff) | |
download | bundler-a3fa04e90133ca42efc7d8dc6cdb16b231b1f964.tar.gz |
Pass `-z` arg to git ls-files & split on null char
It seems a little bit paranoid to assume there might be a newline or
tab in a file name, but it's perfectly valid on many systems. When such
a character exists in a filename, `git ls-files` will return something
like `"file\nname"` in its listing, which is problematic because the
calling code expects neither the escaped whitespace nor the quotes.
By passing the `-z` argument, git uses the null character as the sep-
arator, never escaping whitespace nor quoting file names.
Additionally, I found I had to use the "\x0" syntax to represent the
null character because "\0" is ambiguous in the context of for instance
`String#sub`.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/install/git_spec.rb | 2 | ||||
-rw-r--r-- | spec/quality_spec.rb | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/spec/install/git_spec.rb b/spec/install/git_spec.rb index f970504d09..1b9f8652ba 100644 --- a/spec/install/git_spec.rb +++ b/spec/install/git_spec.rb @@ -34,7 +34,7 @@ describe "bundle install with git sources" do git = update_git "foo" do |s| s.executables = ["foobar"] # we added this the first time, so keep it now s.files = ["bin/foobar"] # updating git nukes the files list - foospec = s.to_ruby.gsub(/s\.files.*/, 's.files = `git ls-files`.split("\n")') + foospec = s.to_ruby.gsub(/s\.files.*/, 's.files = `git ls-files -z`.split("\x0")') s.write "foo.gemspec", foospec end diff --git a/spec/quality_spec.rb b/spec/quality_spec.rb index baafebc781..9f782bb22b 100644 --- a/spec/quality_spec.rb +++ b/spec/quality_spec.rb @@ -54,7 +54,7 @@ describe "The library itself" do exempt = /\.gitmodules|\.marshal|fixtures|vendor|ssl_certs|LICENSE/ error_messages = [] Dir.chdir(File.expand_path("../..", __FILE__)) do - `git ls-files`.split("\n").each do |filename| + `git ls-files -z`.split("\x0").each do |filename| next if filename =~ exempt error_messages << check_for_tab_characters(filename) error_messages << check_for_extra_spaces(filename) @@ -67,7 +67,7 @@ describe "The library itself" do included = /spec/ error_messages = [] Dir.chdir(File.expand_path("../", __FILE__)) do - `git ls-files`.split("\n").each do |filename| + `git ls-files -z`.split("\x0").each do |filename| next unless filename =~ included error_messages << check_for_spec_defs_with_single_quotes(filename) end |