Module: Selenium::WebDriver::Support::Escaper

Defined in:
build/rb/lib/selenium/webdriver/support/escaper.rb

Class Method Summary collapse

Class Method Details

.escape(str) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'build/rb/lib/selenium/webdriver/support/escaper.rb', line 22

def self.escape(str)
  if str.include?('"') && str.include?("'")
    parts = str.split('"', -1).map { |part| %("#{part}") }

    quoted = parts.join(%(, '"', ))
                  .gsub(/^"", |, ""$/, '')

    "concat(#{quoted})"
  elsif str.include?('"')
    # escape string with just a quote into being single quoted: f"oo -> 'f"oo'
    "'#{str}'"
  else
    # otherwise return the quoted string
    %("#{str}")
  end
end