Permalink
Browse files

Remove windows path separators from content-disposition filename. Issue

  • Loading branch information...
1 parent ed0168f commit 19ac54e992af08fceef677c6ace05ef57b83d9c9 @drbrain drbrain committed Nov 8, 2011
Showing with 17 additions and 1 deletion.
  1. +1 −1 lib/mechanize/parser.rb
  2. +16 −0 test/test_mechanize_parser.rb
@@ -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
@@ -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'

0 comments on commit 19ac54e

Please sign in to comment.