Module: Selenium::WebDriver::Support::Select::Escaper Private

Defined in:
lib/selenium/webdriver/support/select.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Class Method Details

.escape(str) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/selenium/webdriver/support/select.rb', line 291

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