Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support parsing of content disposition header with empty filename #496

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/mechanize/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ def extract_filename full_path = @full_path
end

# Set the filename
if disposition = @response['content-disposition'] then
if (disposition = @response['content-disposition'])
content_disposition =
Mechanize::HTTP::ContentDispositionParser.parse disposition

if content_disposition && content_disposition.filename && content_disposition.filename != '' then
if content_disposition && content_disposition.filename && content_disposition.filename != ''
filename = content_disposition.filename
filename = filename.split(/[\\\/]/).last
filename = filename.rpartition(/[\\\/]/).last
handled = true
end
end
Expand Down
10 changes: 10 additions & 0 deletions test/test_mechanize_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ def test_extract_filename_content_disposition_windows_special
end
end

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

@parser.response = {
'content-disposition' => 'inline; filename="/"'
}

assert_equal '', @parser.extract_filename
end

def test_extract_filename_host
@parser.response = {}
@parser.uri = URI 'http://example'
Expand Down