Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/ruby22/lib64/ruby/2.2.0
File: shellwords.rb
##
[0] Fix | Delete
# == Manipulates strings like the UNIX Bourne shell
[1] Fix | Delete
#
[2] Fix | Delete
# This module manipulates strings according to the word parsing rules
[3] Fix | Delete
# of the UNIX Bourne shell.
[4] Fix | Delete
#
[5] Fix | Delete
# The shellwords() function was originally a port of shellwords.pl,
[6] Fix | Delete
# but modified to conform to POSIX / SUSv3 (IEEE Std 1003.1-2001 [1]).
[7] Fix | Delete
#
[8] Fix | Delete
# === Usage
[9] Fix | Delete
#
[10] Fix | Delete
# You can use Shellwords to parse a string into a Bourne shell friendly Array.
[11] Fix | Delete
#
[12] Fix | Delete
# require 'shellwords'
[13] Fix | Delete
#
[14] Fix | Delete
# argv = Shellwords.split('three blind "mice"')
[15] Fix | Delete
# argv #=> ["three", "blind", "mice"]
[16] Fix | Delete
#
[17] Fix | Delete
# Once you've required Shellwords, you can use the #split alias
[18] Fix | Delete
# String#shellsplit.
[19] Fix | Delete
#
[20] Fix | Delete
# argv = "see how they run".shellsplit
[21] Fix | Delete
# argv #=> ["see", "how", "they", "run"]
[22] Fix | Delete
#
[23] Fix | Delete
# Be careful you don't leave a quote unmatched.
[24] Fix | Delete
#
[25] Fix | Delete
# argv = "they all ran after the farmer's wife".shellsplit
[26] Fix | Delete
# #=> ArgumentError: Unmatched double quote: ...
[27] Fix | Delete
#
[28] Fix | Delete
# In this case, you might want to use Shellwords.escape, or its alias
[29] Fix | Delete
# String#shellescape.
[30] Fix | Delete
#
[31] Fix | Delete
# This method will escape the String for you to safely use with a Bourne shell.
[32] Fix | Delete
#
[33] Fix | Delete
# argv = Shellwords.escape("special's.txt")
[34] Fix | Delete
# argv #=> "special\\'s.txt"
[35] Fix | Delete
# system("cat " + argv)
[36] Fix | Delete
#
[37] Fix | Delete
# Shellwords also comes with a core extension for Array, Array#shelljoin.
[38] Fix | Delete
#
[39] Fix | Delete
# argv = %w{ls -lta lib}
[40] Fix | Delete
# system(argv.shelljoin)
[41] Fix | Delete
#
[42] Fix | Delete
# You can use this method to create an escaped string out of an array of tokens
[43] Fix | Delete
# separated by a space. In this example we used the literal shortcut for
[44] Fix | Delete
# Array.new.
[45] Fix | Delete
#
[46] Fix | Delete
# === Authors
[47] Fix | Delete
# * Wakou Aoyama
[48] Fix | Delete
# * Akinori MUSHA <knu@iDaemons.org>
[49] Fix | Delete
#
[50] Fix | Delete
# === Contact
[51] Fix | Delete
# * Akinori MUSHA <knu@iDaemons.org> (current maintainer)
[52] Fix | Delete
#
[53] Fix | Delete
# === Resources
[54] Fix | Delete
#
[55] Fix | Delete
# 1: {IEEE Std 1003.1-2004}[http://pubs.opengroup.org/onlinepubs/009695399/toc.htm]
[56] Fix | Delete
[57] Fix | Delete
module Shellwords
[58] Fix | Delete
# Splits a string into an array of tokens in the same way the UNIX
[59] Fix | Delete
# Bourne shell does.
[60] Fix | Delete
#
[61] Fix | Delete
# argv = Shellwords.split('here are "two words"')
[62] Fix | Delete
# argv #=> ["here", "are", "two words"]
[63] Fix | Delete
#
[64] Fix | Delete
# String#shellsplit is a shortcut for this function.
[65] Fix | Delete
#
[66] Fix | Delete
# argv = 'here are "two words"'.shellsplit
[67] Fix | Delete
# argv #=> ["here", "are", "two words"]
[68] Fix | Delete
def shellsplit(line)
[69] Fix | Delete
words = []
[70] Fix | Delete
field = ''
[71] Fix | Delete
line.scan(/\G\s*(?>([^\s\\\'\"]+)|'([^\']*)'|"((?:[^\"\\]|\\.)*)"|(\\.?)|(\S))(\s|\z)?/m) do
[72] Fix | Delete
|word, sq, dq, esc, garbage, sep|
[73] Fix | Delete
raise ArgumentError, "Unmatched double quote: #{line.inspect}" if garbage
[74] Fix | Delete
field << (word || sq || (dq || esc).gsub(/\\(.)/, '\\1'))
[75] Fix | Delete
if sep
[76] Fix | Delete
words << field
[77] Fix | Delete
field = ''
[78] Fix | Delete
end
[79] Fix | Delete
end
[80] Fix | Delete
words
[81] Fix | Delete
end
[82] Fix | Delete
[83] Fix | Delete
alias shellwords shellsplit
[84] Fix | Delete
[85] Fix | Delete
module_function :shellsplit, :shellwords
[86] Fix | Delete
[87] Fix | Delete
class << self
[88] Fix | Delete
alias split shellsplit
[89] Fix | Delete
end
[90] Fix | Delete
[91] Fix | Delete
# Escapes a string so that it can be safely used in a Bourne shell
[92] Fix | Delete
# command line. +str+ can be a non-string object that responds to
[93] Fix | Delete
# +to_s+.
[94] Fix | Delete
#
[95] Fix | Delete
# Note that a resulted string should be used unquoted and is not
[96] Fix | Delete
# intended for use in double quotes nor in single quotes.
[97] Fix | Delete
#
[98] Fix | Delete
# argv = Shellwords.escape("It's better to give than to receive")
[99] Fix | Delete
# argv #=> "It\\'s\\ better\\ to\\ give\\ than\\ to\\ receive"
[100] Fix | Delete
#
[101] Fix | Delete
# String#shellescape is a shorthand for this function.
[102] Fix | Delete
#
[103] Fix | Delete
# argv = "It's better to give than to receive".shellescape
[104] Fix | Delete
# argv #=> "It\\'s\\ better\\ to\\ give\\ than\\ to\\ receive"
[105] Fix | Delete
#
[106] Fix | Delete
# # Search files in lib for method definitions
[107] Fix | Delete
# pattern = "^[ \t]*def "
[108] Fix | Delete
# open("| grep -Ern #{pattern.shellescape} lib") { |grep|
[109] Fix | Delete
# grep.each_line { |line|
[110] Fix | Delete
# file, lineno, matched_line = line.split(':', 3)
[111] Fix | Delete
# # ...
[112] Fix | Delete
# }
[113] Fix | Delete
# }
[114] Fix | Delete
#
[115] Fix | Delete
# It is the caller's responsibility to encode the string in the right
[116] Fix | Delete
# encoding for the shell environment where this string is used.
[117] Fix | Delete
#
[118] Fix | Delete
# Multibyte characters are treated as multibyte characters, not as bytes.
[119] Fix | Delete
#
[120] Fix | Delete
# Returns an empty quoted String if +str+ has a length of zero.
[121] Fix | Delete
def shellescape(str)
[122] Fix | Delete
str = str.to_s
[123] Fix | Delete
[124] Fix | Delete
# An empty argument will be skipped, so return empty quotes.
[125] Fix | Delete
return "''" if str.empty?
[126] Fix | Delete
[127] Fix | Delete
str = str.dup
[128] Fix | Delete
[129] Fix | Delete
# Treat multibyte characters as is. It is the caller's responsibility
[130] Fix | Delete
# to encode the string in the right encoding for the shell
[131] Fix | Delete
# environment.
[132] Fix | Delete
str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\\\1")
[133] Fix | Delete
[134] Fix | Delete
# A LF cannot be escaped with a backslash because a backslash + LF
[135] Fix | Delete
# combo is regarded as a line continuation and simply ignored.
[136] Fix | Delete
str.gsub!(/\n/, "'\n'")
[137] Fix | Delete
[138] Fix | Delete
return str
[139] Fix | Delete
end
[140] Fix | Delete
[141] Fix | Delete
module_function :shellescape
[142] Fix | Delete
[143] Fix | Delete
class << self
[144] Fix | Delete
alias escape shellescape
[145] Fix | Delete
end
[146] Fix | Delete
[147] Fix | Delete
# Builds a command line string from an argument list, +array+.
[148] Fix | Delete
#
[149] Fix | Delete
# All elements are joined into a single string with fields separated by a
[150] Fix | Delete
# space, where each element is escaped for the Bourne shell and stringified
[151] Fix | Delete
# using +to_s+.
[152] Fix | Delete
#
[153] Fix | Delete
# ary = ["There's", "a", "time", "and", "place", "for", "everything"]
[154] Fix | Delete
# argv = Shellwords.join(ary)
[155] Fix | Delete
# argv #=> "There\\'s a time and place for everything"
[156] Fix | Delete
#
[157] Fix | Delete
# Array#shelljoin is a shortcut for this function.
[158] Fix | Delete
#
[159] Fix | Delete
# ary = ["Don't", "rock", "the", "boat"]
[160] Fix | Delete
# argv = ary.shelljoin
[161] Fix | Delete
# argv #=> "Don\\'t rock the boat"
[162] Fix | Delete
#
[163] Fix | Delete
# You can also mix non-string objects in the elements as allowed in Array#join.
[164] Fix | Delete
#
[165] Fix | Delete
# output = `#{['ps', '-p', $$].shelljoin}`
[166] Fix | Delete
#
[167] Fix | Delete
def shelljoin(array)
[168] Fix | Delete
array.map { |arg| shellescape(arg) }.join(' ')
[169] Fix | Delete
end
[170] Fix | Delete
[171] Fix | Delete
module_function :shelljoin
[172] Fix | Delete
[173] Fix | Delete
class << self
[174] Fix | Delete
alias join shelljoin
[175] Fix | Delete
end
[176] Fix | Delete
end
[177] Fix | Delete
[178] Fix | Delete
class String
[179] Fix | Delete
# call-seq:
[180] Fix | Delete
# str.shellsplit => array
[181] Fix | Delete
#
[182] Fix | Delete
# Splits +str+ into an array of tokens in the same way the UNIX
[183] Fix | Delete
# Bourne shell does.
[184] Fix | Delete
#
[185] Fix | Delete
# See Shellwords.shellsplit for details.
[186] Fix | Delete
def shellsplit
[187] Fix | Delete
Shellwords.split(self)
[188] Fix | Delete
end
[189] Fix | Delete
[190] Fix | Delete
# call-seq:
[191] Fix | Delete
# str.shellescape => string
[192] Fix | Delete
#
[193] Fix | Delete
# Escapes +str+ so that it can be safely used in a Bourne shell
[194] Fix | Delete
# command line.
[195] Fix | Delete
#
[196] Fix | Delete
# See Shellwords.shellescape for details.
[197] Fix | Delete
def shellescape
[198] Fix | Delete
Shellwords.escape(self)
[199] Fix | Delete
end
[200] Fix | Delete
end
[201] Fix | Delete
[202] Fix | Delete
class Array
[203] Fix | Delete
# call-seq:
[204] Fix | Delete
# array.shelljoin => string
[205] Fix | Delete
#
[206] Fix | Delete
# Builds a command line string from an argument list +array+ joining
[207] Fix | Delete
# all elements escaped for the Bourne shell and separated by a space.
[208] Fix | Delete
#
[209] Fix | Delete
# See Shellwords.shelljoin for details.
[210] Fix | Delete
def shelljoin
[211] Fix | Delete
Shellwords.join(self)
[212] Fix | Delete
end
[213] Fix | Delete
end
[214] Fix | Delete
[215] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function