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.


272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/selenium/webdriver/support/select.rb', line 272

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