Skip to content

Commit

Permalink
Support paths using 2-byte characters
Browse files Browse the repository at this point in the history
The following error occurs when the path contains 2-byte characters.

```
URI::InvalidURIError:
  URI must be ascii only "http://localhost:4567/\u732B"
```

Referring to the Capybara implementation, use Addressable instead of URI
to support 2-byte characters.
refs: https://github.com/teamcapybara/capybara/blob/3.40.0/lib/capybara/session.rb#L261
  • Loading branch information
sinsoku committed Jan 28, 2024
1 parent f46952e commit ef4cdc5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions capybara-playwright.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.required_ruby_version = '>= 2.4'
spec.add_dependency 'addressable'
spec.add_dependency 'capybara'
spec.add_dependency 'playwright-ruby-client', '>= 1.16.0'
spec.add_development_dependency 'allure-rspec'
Expand Down
5 changes: 3 additions & 2 deletions lib/capybara/playwright/browser.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'addressable/uri'
require_relative './tmpdir_owner'

module Capybara
Expand Down Expand Up @@ -74,9 +75,9 @@ def visit(path)
assert_page_alive {
url =
if Capybara.app_host
URI(Capybara.app_host).merge(path)
Addressable::URI.parse(Capybara.app_host) + path
elsif Capybara.default_host
URI(Capybara.default_host).merge(path)
Addressable::URI.parse(Capybara.default_host) + path
else
path
end
Expand Down
10 changes: 10 additions & 0 deletions spec/feature/assertion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
sinatra.get '/finish.html' do
'finish'
end

sinatra.get '/猫' do
'cat'
end
end

it 'survives against navigation' do
Expand All @@ -56,4 +60,10 @@
refresh
expect(page).to have_content('finish')
end

it 'can access paths using 2-byte characters' do
visit '/猫'

expect(page).to have_content('cat')
end
end

0 comments on commit ef4cdc5

Please sign in to comment.