Skip to content

Commit

Permalink
Fix visiting urls with non-http(s) schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
abotalov committed Jun 19, 2014
1 parent 6ba0c70 commit bb942e9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/capybara/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,15 @@ def visit(url)

@touched = true

if url !~ /^http/ and Capybara.app_host
url_relative = URI.parse(url.to_s).scheme.nil?

if url_relative && Capybara.app_host
url = Capybara.app_host + url.to_s
url_relative = false
end

if @server
url = "http://#{@server.host}:#{@server.port}" + url.to_s unless url =~ /^http/
url = "http://#{@server.host}:#{@server.port}" + url.to_s if url_relative

if Capybara.always_include_port
uri = URI.parse(url)
Expand Down
5 changes: 5 additions & 0 deletions lib/capybara/spec/session/visit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
end.to raise_error(TestApp::TestAppError)
end

it "should be able to open non-http url", requires: [:about_scheme] do
@session.visit("about:blank")
@session.assert_no_selector :xpath, "/html/body/*"
end

context "when Capybara.always_include_port is true" do

let(:root_uri) do
Expand Down
3 changes: 2 additions & 1 deletion spec/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class TestClass
:frames,
:windows,
:server,
:hover
:hover,
:about_scheme,
]

RSpec.describe Capybara::DSL do
Expand Down
3 changes: 2 additions & 1 deletion spec/rack_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module TestSessions
:frames,
:windows,
:server,
:hover
:hover,
:about_scheme,
]

RSpec.describe Capybara::Session do
Expand Down

0 comments on commit bb942e9

Please sign in to comment.