From ef4cdc51f75f3d34d42ed2f474eb10f9a2e60888 Mon Sep 17 00:00:00 2001 From: Takumi Shotoku Date: Sun, 28 Jan 2024 12:51:53 +0900 Subject: [PATCH] Support paths using 2-byte characters 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 --- capybara-playwright.gemspec | 1 + lib/capybara/playwright/browser.rb | 5 +++-- spec/feature/assertion_spec.rb | 10 ++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/capybara-playwright.gemspec b/capybara-playwright.gemspec index 14838c9..d37a9df 100644 --- a/capybara-playwright.gemspec +++ b/capybara-playwright.gemspec @@ -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' diff --git a/lib/capybara/playwright/browser.rb b/lib/capybara/playwright/browser.rb index c072e0d..e1a64c8 100644 --- a/lib/capybara/playwright/browser.rb +++ b/lib/capybara/playwright/browser.rb @@ -1,3 +1,4 @@ +require 'addressable/uri' require_relative './tmpdir_owner' module Capybara @@ -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 diff --git a/spec/feature/assertion_spec.rb b/spec/feature/assertion_spec.rb index 27f5e89..4033dda 100644 --- a/spec/feature/assertion_spec.rb +++ b/spec/feature/assertion_spec.rb @@ -39,6 +39,10 @@ sinatra.get '/finish.html' do 'finish' end + + sinatra.get '/猫' do + 'cat' + end end it 'survives against navigation' do @@ -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