From 4b9639229389905dbdf6043fa51026417730a6d5 Mon Sep 17 00:00:00 2001 From: Dmitry Vorotilin Date: Thu, 16 Apr 2015 16:33:39 +0300 Subject: [PATCH] #418 Whitespace character remained unencoded --- CHANGELOG.md | 4 +- lib/capybara/poltergeist/client/agent.coffee | 5 ++- .../poltergeist/client/compiled/agent.js | 2 +- spec/integration/session_spec.rb | 37 +++++++++++++++---- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d6844af..88b397da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,12 @@ * Persist browser state on Ruby side (Brian Ledbetter) [Issue #564] * Add support for key modifiers for send_keys (Sarah Mogin) [Issue #420] * Drag by offset support in native element (phoenixek12) -* Fire focus related events on selecting a select box option (Rumen Paletov) [Issue #607] +* Fire focus related events on selecting a select box option + (Rumen Paletov) [Issue #607] #### Bug fixes #### * Support reading text from SVG elements (Oliver Searle-Barnes) +* Whitespace character in `current_url` remained unencoded [Issue #418] ### 1.6.0 ### diff --git a/lib/capybara/poltergeist/client/agent.coffee b/lib/capybara/poltergeist/client/agent.coffee index dfed9971..afd58e7e 100644 --- a/lib/capybara/poltergeist/client/agent.coffee +++ b/lib/capybara/poltergeist/client/agent.coffee @@ -24,8 +24,11 @@ class PoltergeistAgent else throw error + # Somehow PhantomJS returns all characters(brackets, etc) properly encoded + # except whitespace character in pathname part of the location. This hack + # is intended to fix this up. currentUrl: -> - window.location.href + window.location.href.replace(/\ /g, '%20') find: (method, selector, within = document) -> try diff --git a/lib/capybara/poltergeist/client/compiled/agent.js b/lib/capybara/poltergeist/client/compiled/agent.js index 9539a238..2d915fce 100644 --- a/lib/capybara/poltergeist/client/compiled/agent.js +++ b/lib/capybara/poltergeist/client/compiled/agent.js @@ -44,7 +44,7 @@ PoltergeistAgent = (function() { }; PoltergeistAgent.prototype.currentUrl = function() { - return window.location.href; + return window.location.href.replace(/\ /g, '%20'); }; PoltergeistAgent.prototype.find = function(method, selector, within) { diff --git a/spec/integration/session_spec.rb b/spec/integration/session_spec.rb index 28d76b45..69150e35 100644 --- a/spec/integration/session_spec.rb +++ b/spec/integration/session_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' -Capybara::SpecHelper.run_specs TestSessions::Poltergeist, 'Poltergeist', capybara_skip: [:modals] +skip = [:modals] +skip << :windows if ENV['TRAVIS'] +Capybara::SpecHelper.run_specs TestSessions::Poltergeist, 'Poltergeist', capybara_skip: skip describe Capybara::Session do context 'with poltergeist driver' do @@ -383,14 +385,33 @@ expect(@session.evaluate_script('window.last_hashchange')).to eq('#foo') end - it 'supports retrieving the current_path with escaped characters' do - @session.visit '/poltergeist/arbitrary_path/200/foo%20bar' - expect(@session.current_path).to eq('/poltergeist/arbitrary_path/200/foo%20bar') - end + context 'current_url' do + let(:request_uri) { URI.parse(@session.current_url).request_uri } + + it 'supports whitespace characters' do + @session.visit '/poltergeist/arbitrary_path/200/foo%20bar%20baz' + expect(@session.current_path).to eq('/poltergeist/arbitrary_path/200/foo%20bar%20baz') + end + + it 'supports escaped characters' do + @session.visit '/poltergeist/arbitrary_path/200/foo?a%5Bb%5D=c' + expect(request_uri).to eq('/poltergeist/arbitrary_path/200/foo?a%5Bb%5D=c') + end - it 'supports retrieving the current_url with escaped characters' do - @session.visit '/poltergeist/arbitrary_path/200/foo?a%5Bb%5D=c' - expect(URI.parse(@session.current_url).request_uri).to eq('/poltergeist/arbitrary_path/200/foo?a%5Bb%5D=c') + it 'supports allowed characters' do + @session.visit '/poltergeist/arbitrary_path/200/foo?a[b]=c' + expect(request_uri).to eq('/poltergeist/arbitrary_path/200/foo?a%5Bb%5D=c') + end + + it 'supports url in parameter' do + @session.visit "/poltergeist/arbitrary_path/200/foo%20asd?a=http://example.com/asd%20asd" + expect(request_uri).to eq('/poltergeist/arbitrary_path/200/foo%20asd?a=http://example.com/asd%20asd') + end + + it 'supports restricted characters " []:/+&="' do + @session.visit "/poltergeist/arbitrary_path/200/foo?a=%20%5B%5D%3A%2F%2B%26%3D" + expect(request_uri).to eq('/poltergeist/arbitrary_path/200/foo?a=%20%5B%5D%3A%2F%2B%26%3D') + end end context 'dragging support' do