Skip to content

Instantly share code, notes, and snippets.

@bonkydog
Created November 13, 2012 06:13
Show Gist options
  • Save bonkydog/4064260 to your computer and use it in GitHub Desktop.
Save bonkydog/4064260 to your computer and use it in GitHub Desktop.
escape single quotes for xpath in ruby
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