Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge remote branch 'wincent/alt-bugfix-issue-7'
  • Loading branch information
Jonas Nicklas and Peter Gromark authored and jnicklas committed Nov 30, 2009
2 parents a78f969 + 86246be commit 6e11333
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/capybara/session.rb
Expand Up @@ -82,7 +82,7 @@ def body
end

def has_content?(content)
has_xpath?("//*[contains(.,'#{content}')]")
has_xpath?("//*[contains(.,#{sanitized_xpath_string(content)})]")
end

def has_xpath?(path, options={})
Expand Down Expand Up @@ -197,5 +197,16 @@ def find(locator)
locator = current_scope.to_s + locator
driver.find(locator)
end

def sanitized_xpath_string(string)
if string =~ /'/
string = string.split("'", -1).map do |substr|
"'#{substr}'"
end.join(%q{,"'",})
"concat(#{string})"
else
"'#{string}'"
end
end
end
end
15 changes: 15 additions & 0 deletions spec/session_spec.rb
Expand Up @@ -325,6 +325,21 @@ def extract_results(session)
@session.should_not have_content('xxxxyzzz')
@session.should_not have_content('monkey')
end

it 'should handle single quotes in the content' do
@session.visit('/with-quotes')
@session.should have_content("can't")
end

it 'should handle double quotes in the content' do
@session.visit('/with-quotes')
@session.should have_content(%q{"No," he said})
end

it 'should handle mixed single and double quotes in the content' do
@session.visit('/with-quotes')
@session.should have_content(%q{"you can't do that."})
end
end

describe '#has_xpath?' do
Expand Down
6 changes: 5 additions & 1 deletion spec/test_app.rb
Expand Up @@ -24,7 +24,11 @@ class TestApp < Sinatra::Base
get '/landed' do
"You landed"
end


get '/with-quotes' do
%q{"No," he said, "you can't do that."}
end

get '/form/get' do
'<pre id="results">' + params[:form].to_yaml + '</pre>'
end
Expand Down

0 comments on commit 6e11333

Please sign in to comment.