Skip to content

Commit

Permalink
fix escaping bug when dealing with embedded regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederik Fix committed Sep 12, 2009
1 parent 2a464f8 commit 4342cbb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/selenium/client/javascript_expression_builder.rb
Expand Up @@ -109,7 +109,7 @@ def window_script(expression)
end

def quote_escaped(a_string)
a_string.gsub(/'/, %q<\\\'>)
a_string.gsub(/\\/, "\\\\\\").gsub(/'/, %q<\\\'>)
end
end
end
Expand Down
16 changes: 14 additions & 2 deletions test/unit/selenium/client/javascript_expression_builder_tests.rb
Expand Up @@ -36,7 +36,13 @@
assert_equal "//div[@id=\\'demo-effect-appear\\']",
builder.quote_escaped("//div[@id='demo-effect-appear']")
end


test "quote_escaped escapes backslashes" do
builder = Selenium::Client::JavascriptExpressionBuilder.new
assert_equal "webratlink=evalregex:/Pastry Lovers \\\\(Organizer\\\\)/",
builder.quote_escaped("webratlink=evalregex:/Pastry Lovers \\(Organizer\\)/")
end

test "text_match matches on entire string when pattern is a string" do
builder = Selenium::Client::JavascriptExpressionBuilder.new
assert_equal "element.innerHTML == 'some text'",
Expand All @@ -60,7 +66,13 @@
assert_match(/element\s+=\s+selenium.browserbot.findElement\('a_locator'\);/m,
builder.find_element('a_locator').script)
end


test "find_element should handle embedded evalregex locators" do
builder = Selenium::Client::JavascriptExpressionBuilder.new
assert_match(/element\s+=\s+selenium.browserbot.findElement\('webratlink=evalregex:\/Pastry Lovers \\\\\(Organizer\\\\\)\/'\);/m,
builder.find_element("webratlink=evalregex:/Pastry Lovers \\(Organizer\\)/").script)
end

test "javascript_framework_for :prototype returns JavascriptFrameworks::Prototype" do
builder = Selenium::Client::JavascriptExpressionBuilder.new
assert_equal Selenium::Client::JavascriptFrameworks::Prototype,
Expand Down

0 comments on commit 4342cbb

Please sign in to comment.