Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby18/lib64/ruby/1.8
File: shellwords.rb
#
[0] Fix | Delete
# shellwords.rb: Manipulates strings a la UNIX Bourne shell
[1] Fix | Delete
#
[2] Fix | Delete
[3] Fix | Delete
#
[4] Fix | Delete
# This module manipulates strings according to the word parsing rules
[5] Fix | Delete
# of the UNIX Bourne shell.
[6] Fix | Delete
#
[7] Fix | Delete
# The shellwords() function was originally a port of shellwords.pl,
[8] Fix | Delete
# but modified to conform to POSIX / SUSv3 (IEEE Std 1003.1-2001).
[9] Fix | Delete
#
[10] Fix | Delete
# Authors:
[11] Fix | Delete
# - Wakou Aoyama
[12] Fix | Delete
# - Akinori MUSHA <knu@iDaemons.org>
[13] Fix | Delete
#
[14] Fix | Delete
# Contact:
[15] Fix | Delete
# - Akinori MUSHA <knu@iDaemons.org> (current maintainer)
[16] Fix | Delete
#
[17] Fix | Delete
module Shellwords
[18] Fix | Delete
#
[19] Fix | Delete
# Splits a string into an array of tokens in the same way the UNIX
[20] Fix | Delete
# Bourne shell does.
[21] Fix | Delete
#
[22] Fix | Delete
# argv = Shellwords.split('here are "two words"')
[23] Fix | Delete
# argv #=> ["here", "are", "two words"]
[24] Fix | Delete
#
[25] Fix | Delete
# +String#shellsplit+ is a shorthand for this function.
[26] Fix | Delete
#
[27] Fix | Delete
# argv = 'here are "two words"'.shellsplit
[28] Fix | Delete
# argv #=> ["here", "are", "two words"]
[29] Fix | Delete
#
[30] Fix | Delete
def shellsplit(line)
[31] Fix | Delete
line = String.new(line) rescue
[32] Fix | Delete
raise(ArgumentError, "Argument must be a string")
[33] Fix | Delete
line.lstrip!
[34] Fix | Delete
words = []
[35] Fix | Delete
until line.empty?
[36] Fix | Delete
field = ''
[37] Fix | Delete
loop do
[38] Fix | Delete
if line.sub!(/\A"(([^"\\]|\\.)*)"/, '') then
[39] Fix | Delete
snippet = $1.gsub(/\\(.)/, '\1')
[40] Fix | Delete
elsif line =~ /\A"/ then
[41] Fix | Delete
raise ArgumentError, "Unmatched double quote: #{line}"
[42] Fix | Delete
elsif line.sub!(/\A'([^']*)'/, '') then
[43] Fix | Delete
snippet = $1
[44] Fix | Delete
elsif line =~ /\A'/ then
[45] Fix | Delete
raise ArgumentError, "Unmatched single quote: #{line}"
[46] Fix | Delete
elsif line.sub!(/\A\\(.)?/, '') then
[47] Fix | Delete
snippet = $1 || '\\'
[48] Fix | Delete
elsif line.sub!(/\A([^\s\\'"]+)/, '') then
[49] Fix | Delete
snippet = $1
[50] Fix | Delete
else
[51] Fix | Delete
line.lstrip!
[52] Fix | Delete
break
[53] Fix | Delete
end
[54] Fix | Delete
field.concat(snippet)
[55] Fix | Delete
end
[56] Fix | Delete
words.push(field)
[57] Fix | Delete
end
[58] Fix | Delete
words
[59] Fix | Delete
end
[60] Fix | Delete
[61] Fix | Delete
alias shellwords shellsplit
[62] Fix | Delete
[63] Fix | Delete
module_function :shellsplit, :shellwords
[64] Fix | Delete
[65] Fix | Delete
class << self
[66] Fix | Delete
alias split shellsplit
[67] Fix | Delete
end
[68] Fix | Delete
[69] Fix | Delete
#
[70] Fix | Delete
# Escapes a string so that it can be safely used in a Bourne shell
[71] Fix | Delete
# command line.
[72] Fix | Delete
#
[73] Fix | Delete
# Note that a resulted string should be used unquoted and is not
[74] Fix | Delete
# intended for use in double quotes nor in single quotes.
[75] Fix | Delete
#
[76] Fix | Delete
# open("| grep #{Shellwords.escape(pattern)} file") { |pipe|
[77] Fix | Delete
# # ...
[78] Fix | Delete
# }
[79] Fix | Delete
#
[80] Fix | Delete
# +String#shellescape+ is a shorthand for this function.
[81] Fix | Delete
#
[82] Fix | Delete
# open("| grep #{pattern.shellescape} file") { |pipe|
[83] Fix | Delete
# # ...
[84] Fix | Delete
# }
[85] Fix | Delete
#
[86] Fix | Delete
def shellescape(str)
[87] Fix | Delete
# An empty argument will be skipped, so return empty quotes.
[88] Fix | Delete
return "''" if str.empty?
[89] Fix | Delete
[90] Fix | Delete
str = str.dup
[91] Fix | Delete
[92] Fix | Delete
# Process as a single byte sequence because not all shell
[93] Fix | Delete
# implementations are multibyte aware.
[94] Fix | Delete
str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1")
[95] Fix | Delete
[96] Fix | Delete
# A LF cannot be escaped with a backslash because a backslash + LF
[97] Fix | Delete
# combo is regarded as line continuation and simply ignored.
[98] Fix | Delete
str.gsub!(/\n/, "'\n'")
[99] Fix | Delete
[100] Fix | Delete
return str
[101] Fix | Delete
end
[102] Fix | Delete
[103] Fix | Delete
module_function :shellescape
[104] Fix | Delete
[105] Fix | Delete
class << self
[106] Fix | Delete
alias escape shellescape
[107] Fix | Delete
end
[108] Fix | Delete
[109] Fix | Delete
#
[110] Fix | Delete
# Builds a command line string from an argument list +array+ joining
[111] Fix | Delete
# all elements escaped for Bourne shell and separated by a space.
[112] Fix | Delete
#
[113] Fix | Delete
# open('|' + Shellwords.join(['grep', pattern, *files])) { |pipe|
[114] Fix | Delete
# # ...
[115] Fix | Delete
# }
[116] Fix | Delete
#
[117] Fix | Delete
# +Array#shelljoin+ is a shorthand for this function.
[118] Fix | Delete
#
[119] Fix | Delete
# open('|' + ['grep', pattern, *files].shelljoin) { |pipe|
[120] Fix | Delete
# # ...
[121] Fix | Delete
# }
[122] Fix | Delete
#
[123] Fix | Delete
def shelljoin(array)
[124] Fix | Delete
array.map { |arg| shellescape(arg) }.join(' ')
[125] Fix | Delete
end
[126] Fix | Delete
[127] Fix | Delete
module_function :shelljoin
[128] Fix | Delete
[129] Fix | Delete
class << self
[130] Fix | Delete
alias join shelljoin
[131] Fix | Delete
end
[132] Fix | Delete
end
[133] Fix | Delete
[134] Fix | Delete
class String
[135] Fix | Delete
#
[136] Fix | Delete
# call-seq:
[137] Fix | Delete
# str.shellsplit => array
[138] Fix | Delete
#
[139] Fix | Delete
# Splits +str+ into an array of tokens in the same way the UNIX
[140] Fix | Delete
# Bourne shell does. See +Shellwords::shellsplit+ for details.
[141] Fix | Delete
#
[142] Fix | Delete
def shellsplit
[143] Fix | Delete
Shellwords.split(self)
[144] Fix | Delete
end
[145] Fix | Delete
[146] Fix | Delete
#
[147] Fix | Delete
# call-seq:
[148] Fix | Delete
# str.shellescape => string
[149] Fix | Delete
#
[150] Fix | Delete
# Escapes +str+ so that it can be safely used in a Bourne shell
[151] Fix | Delete
# command line. See +Shellwords::shellescape+ for details.
[152] Fix | Delete
#
[153] Fix | Delete
def shellescape
[154] Fix | Delete
Shellwords.escape(self)
[155] Fix | Delete
end
[156] Fix | Delete
end
[157] Fix | Delete
[158] Fix | Delete
class Array
[159] Fix | Delete
#
[160] Fix | Delete
# call-seq:
[161] Fix | Delete
# array.shelljoin => string
[162] Fix | Delete
#
[163] Fix | Delete
# Builds a command line string from an argument list +array+ joining
[164] Fix | Delete
# all elements escaped for Bourne shell and separated by a space.
[165] Fix | Delete
# See +Shellwords::shelljoin+ for details.
[166] Fix | Delete
#
[167] Fix | Delete
def shelljoin
[168] Fix | Delete
Shellwords.join(self)
[169] Fix | Delete
end
[170] Fix | Delete
end
[171] Fix | Delete
[172] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function