Skip to content

Commit

Permalink
hchoroomi: fixing a bug in action.rb that would break downloads of fi…
Browse files Browse the repository at this point in the history
…les with query-parameters in the URL.
  • Loading branch information
jashkenas committed Jun 15, 2010
1 parent d8e9e86 commit d938acf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/cloud_crowd/action.rb
Expand Up @@ -84,7 +84,7 @@ def `(command)

# Convert an unsafe URL into a filesystem-friendly filename.
def safe_filename(url)
url.sub!(/\?.*\Z/, '')
url = url.sub(/\?.*\Z/, '')
ext = File.extname(url)
name = URI.unescape(File.basename(url)).gsub(/[^a-zA-Z0-9_\-.]/, '-').gsub(/-+/, '-')
File.basename(name, ext).gsub('.', '-') + ext
Expand Down
9 changes: 8 additions & 1 deletion test/unit/test_action.rb
Expand Up @@ -42,8 +42,15 @@ class ActionTest < Test::Unit::TestCase
assert name == 'file.pdf'
end

should "not change the original URL when generating a safe filename" do
url = "http://example.com/file.format?parameter=value"
path = @action.safe_filename url
assert url == "http://example.com/file.format?parameter=value"
assert path == "file.format"
end

should "be able to count the number of words in this file" do
assert @action.process == 219
assert @action.process == 247
end

should "raise an exception when backticks fail" do
Expand Down

0 comments on commit d938acf

Please sign in to comment.