Permalink
Browse files

Extended special filename detection to all filenames. Issue #163

  • Loading branch information...
1 parent 074cc2d commit 7c5767193bcb38aa7ae76922fe2eef673f17f51e @drbrain drbrain committed Nov 8, 2011
Showing with 43 additions and 2 deletions.
  1. +7 −2 lib/mechanize/parser.rb
  2. +36 −0 test/test_mechanize_parser.rb
@@ -6,7 +6,7 @@ module Mechanize::Parser
extend Forwardable
- SPECIAL_FILENAME = %w[
+ special_filenames = Regexp.union %w[
AUX
COM1
COM2
@@ -32,6 +32,11 @@ module Mechanize::Parser
]
##
+ # Special filenames that must be escaped
+
+ SPECIAL_FILENAMES = /\A#{special_filenames}/i
+
+ ##
# The URI this file was retrieved from
attr_accessor :uri
@@ -114,7 +119,7 @@ def extract_filename full_path = @full_path
filename << "?#{@uri.query}" if @uri.query
end
- if SPECIAL_FILENAME.include? filename then
+ if SPECIAL_FILENAMES =~ filename then
filename = "_#{filename}"
end
@@ -184,6 +184,42 @@ def test_extract_filename_uri_slash
assert_equal 'example/foo/index.html', @parser.extract_filename(true)
end
+ def test_extract_filename_windows_special
+ @parser.uri = URI 'http://example'
+ @parser.response = {}
+
+ windows_special = %w[
+ AUX
+ COM1
+ COM2
+ COM3
+ COM4
+ COM5
+ COM6
+ COM7
+ COM8
+ COM9
+ CON
+ LPT1
+ LPT2
+ LPT3
+ LPT4
+ LPT5
+ LPT6
+ LPT7
+ LPT8
+ LPT9
+ NUL
+ PRN
+ ]
+
+ windows_special.each do |special|
+ @parser.uri += "/#{special}"
+
+ assert_equal "_#{special}.html", @parser.extract_filename
+ end
+ end
+
def test_fill_header
@parser.fill_header 'a' => 'b'

0 comments on commit 7c57671

Please sign in to comment.