123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Defined in: rb/lib/selenium/webdriver/support/escaper.rb

Class Method Summary

Class Method Details

.escape(str)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/support/escaper.rb', line 24

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