Module: ShellEscape
- Defined in:
- lib/shell_escape.rb
Overview
Escape module provides several escape functions.
-
shell command
modified to work only with shell
Class Method Summary collapse
-
.command(*args) ⇒ Object
Escape.shell_command composes a sequence of words to a single shell command line.
-
.word(word) ⇒ Object
Escape.shell_single_word quotes shell meta characters.
Class Method Details
.command(*args) ⇒ Object
Escape.shell_command composes a sequence of words to a single shell command line. All shell meta characters are quoted and the words are concatenated with interleaving space.
38 39 40 |
# File 'lib/shell_escape.rb', line 38 def command(*args) args.map{ |arg| word(arg) } * ' ' end |
.word(word) ⇒ Object
Escape.shell_single_word quotes shell meta characters.
The result string is always single shell word, even if the argument is “”.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/shell_escape.rb', line 46 def word(word) word = word.to_s if word.empty? "''" elsif %r{\A[0-9A-Za-z+,./:=@_-]+\z} =~ word word else result = '' word.scan(/('+)|[^']+/) { if $1 result << %q{\'} * $1.length else result << "'#{$&}'" end } result end end |