Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/inplace.rb

Instance Method Summary collapse

Instance Method Details

#shellescapeObject



473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/inplace.rb', line 473

def shellescape
  # An empty argument will be skipped, so return empty quotes.
  return "''" if empty?

  str = dup

  # Process as a single byte sequence because not all shell
  # implementations are multibyte aware.
  str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1")

  # A LF cannot be escaped with a backslash because a backslash + LF
  # combo is regarded as line continuation and simply ignored.
  str.gsub!(/\n/, "'\n'")

  return str
end