Skip to content

Commit

Permalink
Handle files with spaces correctly in encoding_for
Browse files Browse the repository at this point in the history
When passed a file name with a space, we end up calling
`file` without escaping the spaces (and other special characters).
This most likely causes calling `file` on a nonexistent file.
The upload then appears to hang, and eventually the job is terminated.

This commit fixes that.
  • Loading branch information
BanzaiMan committed Oct 28, 2015
1 parent 18554b0 commit bcdbd24
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/dpl/provider.rb
Expand Up @@ -210,7 +210,7 @@ def detect_encoding?
end

def encoding_for(path)
file_cmd_output = `file #{path}`
file_cmd_output = `file '#{path}'`
case file_cmd_output
when /gzip compressed/
'gzip'
Expand Down
8 changes: 7 additions & 1 deletion spec/provider_spec.rb
Expand Up @@ -150,7 +150,13 @@
describe "#encoding_for" do
example do
path = 'foo.js'
expect(provider).to receive(:`).at_least(1).times.with("file #{path}").and_return('gzip compressed')
expect(provider).to receive(:`).at_least(1).times.with("file '#{path}'").and_return("#{path}: gzip compressed")
expect(provider.encoding_for(path)).to eq('gzip')
end

example do
path = 'file with a space'
expect(provider).to receive(:`).at_least(1).times.with("file '#{path}'").and_return("#{path}: empty")
expect(provider.encoding_for(path)).to eq('gzip')
end
end
Expand Down

0 comments on commit bcdbd24

Please sign in to comment.