Skip to content

Commit

Permalink
Merge pull request #496 from erated/fix_parsing_empty_filename_conten…
Browse files Browse the repository at this point in the history
…t_disposition

support parsing of content disposition header with empty filename
  • Loading branch information
knu committed Jun 2, 2018
2 parents 3feaa04 + fa17981 commit 7db937e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
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

0 comments on commit 7db937e

Please sign in to comment.