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

Mechanize::FileConnection not working in windows #483

Closed
pocari opened this issue Aug 8, 2016 · 1 comment · Fixed by #575
Closed

Mechanize::FileConnection not working in windows #483

pocari opened this issue Aug 8, 2016 · 1 comment · Fixed by #575
Milestone

Comments

@pocari
Copy link

pocari commented Aug 8, 2016

my environment

ruby 2.1.6p336 (2015-04-13 revision 50298) [x64-mingw32]
mechanize 2.7.4

problem

In Windows, URI::Generic#path returns path which not include drive letter

e.g)

URI.parse('C:/temp/foo.txt').path
=> "/temp/foo.txt"

Parsing file which exists in C drive, 404 error occured during executing ruby script which exists in D drive.
I think Mechanize is trying to read file in D drive because uri.path is not include drive letter.

vendor/bundle/ruby/2.1.0/gems/mechanize-2.7.4/lib/mechanize/file_response.rb:12:in `read_body': 404 => Net::HTTPNotFound for file:/temp/xxx.html -- Mechanize::ResponseCodeError (Mechanize::ResponseCodeError)

so, I have worked around by the following monkey patch.
(uri.host is drive letter)

Mechanize::FileConnection

class Mechanize::FileConnection
  def request uri, request
    if RUBY_PLATFORM =~ /mingw/
      yield Mechanize::FileResponse.new Mechanize::Util.uri_unescape uri.host + ":" + uri.path
    else
      yield Mechanize::FileResponse.new Mechanize::Util.uri_unescape uri.path
    end
  end
end

Are there good method to fix this problem ?

@flavorjones
Copy link
Member

Will be fixed in v2.8.0

@flavorjones flavorjones added this to the v2.8.0 milestone Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants