Skip to content

Commit

Permalink
teampoltergeist#418 Whitespace character remained unencoded
Browse files Browse the repository at this point in the history
  • Loading branch information
route committed Apr 16, 2015
1 parent 9b2b232 commit 4b96392
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###

Expand Down
5 changes: 4 additions & 1 deletion lib/capybara/poltergeist/client/agent.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/poltergeist/client/compiled/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
37 changes: 29 additions & 8 deletions spec/integration/session_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4b96392

Please sign in to comment.