Sha256: e9f3fa19ad9943ace369f9bc5b6ea0e73937a525e7444889a6bff74dc3e4066c

Contents?: true

Size: 787 Bytes

Versions: 8

Compression:

Stored size: 787 Bytes

Contents

# A set of utilities that can be used as a mixin.
module RSpecSystem::Util
  # This is the shellescape method from shellwords from ruby-2.0.0
  #
  # @param str [String] string to escape
  # @return [String] returns escaped string
  def shellescape(str)
    str = str.to_s

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

    str = str.dup

    # Treat multibyte characters as is.  It is caller's responsibility
    # to encode the string in the right encoding for the shell
    # environment.
    str.gsub!(/([^A-Za-z0-9_\-.,:\/@\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
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rspec-system-1.7.1 lib/rspec-system/util.rb
rspec-system-2.0.0 lib/rspec-system/util.rb
rspec-system-1.7.0 lib/rspec-system/util.rb
rspec-system-1.6.0 lib/rspec-system/util.rb
rspec-system-1.5.0 lib/rspec-system/util.rb
rspec-system-1.4.0 lib/rspec-system/util.rb
rspec-system-1.3.0 lib/rspec-system/util.rb
rspec-system-1.2.1 lib/rspec-system/util.rb