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.



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/selenium/webdriver/support/select.rb', line 301

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