Created
November 13, 2012 06:13
-
-
Save bonkydog/4064260 to your computer and use it in GitHub Desktop.
escape single quotes for xpath in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def escape_single_quotes_for_xpath(string) | |
if string =~ /'/ | |
%[concat('] + string.gsub(/'/, %[', "'", ']) + %[')] # horribly, this is how you escape single quotes in XPath. | |
else | |
%['#{string}'] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment