Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Extended special filename detection to all filenames. Issue #163

  • Loading branch information...
commit 7c5767193bcb38aa7ae76922fe2eef673f17f51e 1 parent 074cc2d
@drbrain drbrain authored
Showing with 43 additions and 2 deletions.
  1. +7 −2 lib/mechanize/parser.rb
  2. +36 −0 test/test_mechanize_parser.rb
View
9 lib/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
View
36 test/test_mechanize_parser.rb
@@ -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'
Please sign in to comment.
Something went wrong with that request. Please try again.