1
0
Fork 0
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:
Thomas Walpole 2022-05-08 12:21:28 -07:00 committed by GitHub
commit 2f4a426ee7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 2 deletions

View file

@ -1,3 +1,10 @@
# Version 3.37.1
Relesae date: unreleased
### Fixed
* Regression in rack-test visit - Issue #2548
# Version 3.37.0 # Version 3.37.0
Release date: 2022-05-07 Release date: 2022-05-07

View file

@ -20,6 +20,8 @@ class Capybara::RackTest::Browser
end end
def visit(path, **attributes) def visit(path, **attributes)
@new_visit_request = true
reset_cache!
reset_host! reset_host!
process_and_follow_redirects(:get, path, attributes) process_and_follow_redirects(:get, path, attributes)
end end
@ -45,7 +47,6 @@ class Capybara::RackTest::Browser
def process_and_follow_redirects(method, path, attributes = {}, env = {}) def process_and_follow_redirects(method, path, attributes = {}, env = {})
@current_fragment = build_uri(path).fragment @current_fragment = build_uri(path).fragment
process(method, path, attributes, env) process(method, path, attributes, env)
return unless driver.follow_redirects? return unless driver.follow_redirects?
driver.redirect_limit.times do 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_scheme, @current_host, @current_port = new_uri.select(:scheme, :host, :port)
@current_fragment = new_uri.fragment || @current_fragment @current_fragment = new_uri.fragment || @current_fragment
reset_cache! reset_cache!
@new_visit_request = false
send(method, new_uri.to_s, attributes, env.merge(options[:headers] || {})) send(method, new_uri.to_s, attributes, env.merge(options[:headers] || {}))
end end
@ -127,6 +129,18 @@ class Capybara::RackTest::Browser
dom.title dom.title
end 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 protected
def base_href def base_href

View file

@ -214,5 +214,11 @@ Capybara::SpecHelper.spec '#visit' do
@session.click_link('Bare query') @session.click_link('Bare query')
expect(@session).to have_current_path('/?a=3') expect(@session).to have_current_path('/?a=3')
end 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
end end

View file

@ -193,6 +193,22 @@ class TestApp < Sinatra::Base
HTML HTML
end 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 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';" 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 <<-HTML

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
module Capybara module Capybara
VERSION = '3.37.0' VERSION = '3.37.1'
end end