mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Merge pull request #2549 from teamcapybara/Issue2548_new_visit_uri_regression
Fix pollution of rack-test visit url from previous visit
This commit is contained in:
commit
2f4a426ee7
5 changed files with 45 additions and 2 deletions
|
@ -1,3 +1,10 @@
|
|||
# Version 3.37.1
|
||||
Relesae date: unreleased
|
||||
|
||||
### Fixed
|
||||
|
||||
* Regression in rack-test visit - Issue #2548
|
||||
|
||||
# Version 3.37.0
|
||||
Release date: 2022-05-07
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ class Capybara::RackTest::Browser
|
|||
end
|
||||
|
||||
def visit(path, **attributes)
|
||||
@new_visit_request = true
|
||||
reset_cache!
|
||||
reset_host!
|
||||
process_and_follow_redirects(:get, path, attributes)
|
||||
end
|
||||
|
@ -45,7 +47,6 @@ class Capybara::RackTest::Browser
|
|||
def process_and_follow_redirects(method, path, attributes = {}, env = {})
|
||||
@current_fragment = build_uri(path).fragment
|
||||
process(method, path, attributes, env)
|
||||
|
||||
return unless driver.follow_redirects?
|
||||
|
||||
driver.redirect_limit.times do
|
||||
|
@ -69,6 +70,7 @@ class Capybara::RackTest::Browser
|
|||
@current_scheme, @current_host, @current_port = new_uri.select(:scheme, :host, :port)
|
||||
@current_fragment = new_uri.fragment || @current_fragment
|
||||
reset_cache!
|
||||
@new_visit_request = false
|
||||
send(method, new_uri.to_s, attributes, env.merge(options[:headers] || {}))
|
||||
end
|
||||
|
||||
|
@ -127,6 +129,18 @@ class Capybara::RackTest::Browser
|
|||
dom.title
|
||||
end
|
||||
|
||||
def last_request
|
||||
raise Rack::Test::Error if @new_visit_request
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def last_response
|
||||
raise Rack::Test::Error if @new_visit_request
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def base_href
|
||||
|
|
|
@ -214,5 +214,11 @@ Capybara::SpecHelper.spec '#visit' do
|
|||
@session.click_link('Bare query')
|
||||
expect(@session).to have_current_path('/?a=3')
|
||||
end
|
||||
|
||||
it 'should not use the base href with a new visit call' do
|
||||
@session.visit('/base/with_other_base')
|
||||
@session.visit('with_html')
|
||||
expect(@session).to have_current_path('/with_html')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -193,6 +193,22 @@ class TestApp < Sinatra::Base
|
|||
HTML
|
||||
end
|
||||
|
||||
get '/base/with_other_base' do
|
||||
<<-HTML
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<base href="/base/">
|
||||
<title>Origin</title>
|
||||
</head>
|
||||
<body>
|
||||
<a href="with_title">Title page</a>
|
||||
<a href="?a=3">Bare query</a>
|
||||
</body>
|
||||
</html>
|
||||
HTML
|
||||
end
|
||||
|
||||
get '/csp' do
|
||||
response.headers['Content-Security-Policy'] = "default-src 'none'; connect-src 'self'; base-uri 'none'; font-src 'self'; img-src 'self' data:; object-src 'none'; script-src 'self' 'nonce-jAviMuMisoTisVXjgLoWdA=='; style-src 'self' 'nonce-jAviMuMisoTisVXjgLoWdA=='; form-action 'self';"
|
||||
<<-HTML
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Capybara
|
||||
VERSION = '3.37.0'
|
||||
VERSION = '3.37.1'
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue