Skip to content

Commit

Permalink
Remove windows path separators from content-disposition filename. Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Nov 8, 2011
1 parent ed0168f commit 19ac54e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mechanize/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def extract_filename full_path = @full_path
filename = v if k && k.downcase == 'filename'
end

filename = File.split(filename).last
filename = filename.split(/[\\\/]/).last
elsif @uri then
filename << '.html' unless filename =~ /\./
filename << "?#{@uri.query}" if @uri.query
Expand Down
16 changes: 16 additions & 0 deletions test/test_mechanize_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ def test_extract_filename_content_disposition_path
assert_equal 'example/genome.jpeg', @parser.extract_filename(true)
end

def test_extract_filename_content_disposition_path_windows
@parser.uri = URI 'http://example'

@parser.response = {
'content-disposition' => 'attachment; filename=..\\genome.jpeg'
}

assert_equal 'example/genome.jpeg', @parser.extract_filename(true)

@parser.response = {
'content-disposition' => 'attachment; filename=foo\\genome.jpeg'
}

assert_equal 'example/genome.jpeg', @parser.extract_filename(true)
end

def test_extract_filename_content_disposition_full_path
@parser.uri = URI 'http://example/foo'

Expand Down

0 comments on commit 19ac54e

Please sign in to comment.