rubysl-shellwords 0.0.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/.travis.yml +7 -0
- data/README.md +2 -2
- data/Rakefile +0 -1
- data/lib/rubysl/shellwords.rb +2 -0
- data/lib/rubysl/shellwords/shellwords.rb +172 -0
- data/lib/{rubysl-shellwords → rubysl/shellwords}/version.rb +1 -1
- data/lib/shellwords.rb +1 -0
- data/rubysl-shellwords.gemspec +18 -18
- data/spec/shellwords_spec.rb +28 -0
- metadata +69 -88
- data/lib/rubysl-shellwords.rb +0 -7
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7218a87d72d7ebbf3905a49f386ca8e8ff85b3d3
|
4
|
+
data.tar.gz: 1bf9fa5994639347dc7f5ea40c7fc3e5ce4b5aa9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0be3c1d16ecb39bb9a64ace53f6156f953b754c41579471752bbfdc2164b55d082715697a4df271d18c3627be530bf5be999a55a40a7e27dd9ab06f40f730db9
|
7
|
+
data.tar.gz: 29b72f1bbc93adcdf7011f757fceded2e35fd49e464052bb6dd3d7203488db7dc7362be297cb9a057edb2acf14d422fb4fdebbe6d890f9ad6b4ff7acc9719775
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Rubysl::Shellwords
|
2
2
|
|
3
3
|
TODO: Write a gem description
|
4
4
|
|
@@ -24,6 +24,6 @@ TODO: Write usage instructions here
|
|
24
24
|
|
25
25
|
1. Fork it
|
26
26
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am '
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
28
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
29
|
5. Create new Pull Request
|
data/Rakefile
CHANGED
@@ -0,0 +1,172 @@
|
|
1
|
+
#
|
2
|
+
# shellwords.rb: Manipulates strings a la UNIX Bourne shell
|
3
|
+
#
|
4
|
+
|
5
|
+
#
|
6
|
+
# This module manipulates strings according to the word parsing rules
|
7
|
+
# of the UNIX Bourne shell.
|
8
|
+
#
|
9
|
+
# The shellwords() function was originally a port of shellwords.pl,
|
10
|
+
# but modified to conform to POSIX / SUSv3 (IEEE Std 1003.1-2001).
|
11
|
+
#
|
12
|
+
# Authors:
|
13
|
+
# - Wakou Aoyama
|
14
|
+
# - Akinori MUSHA <knu@iDaemons.org>
|
15
|
+
#
|
16
|
+
# Contact:
|
17
|
+
# - Akinori MUSHA <knu@iDaemons.org> (current maintainer)
|
18
|
+
#
|
19
|
+
module Shellwords
|
20
|
+
#
|
21
|
+
# Splits a string into an array of tokens in the same way the UNIX
|
22
|
+
# Bourne shell does.
|
23
|
+
#
|
24
|
+
# argv = Shellwords.split('here are "two words"')
|
25
|
+
# argv #=> ["here", "are", "two words"]
|
26
|
+
#
|
27
|
+
# +String#shellsplit+ is a shorthand for this function.
|
28
|
+
#
|
29
|
+
# argv = 'here are "two words"'.shellsplit
|
30
|
+
# argv #=> ["here", "are", "two words"]
|
31
|
+
#
|
32
|
+
def shellsplit(line)
|
33
|
+
line = String.new(line) rescue
|
34
|
+
raise(ArgumentError, "Argument must be a string")
|
35
|
+
line.lstrip!
|
36
|
+
words = []
|
37
|
+
until line.empty?
|
38
|
+
field = ''
|
39
|
+
loop do
|
40
|
+
if line.sub!(/\A"(([^"\\]|\\.)*)"/, '') then
|
41
|
+
snippet = $1.gsub(/\\(.)/, '\1')
|
42
|
+
elsif line =~ /\A"/ then
|
43
|
+
raise ArgumentError, "Unmatched double quote: #{line}"
|
44
|
+
elsif line.sub!(/\A'([^']*)'/, '') then
|
45
|
+
snippet = $1
|
46
|
+
elsif line =~ /\A'/ then
|
47
|
+
raise ArgumentError, "Unmatched single quote: #{line}"
|
48
|
+
elsif line.sub!(/\A\\(.)?/, '') then
|
49
|
+
snippet = $1 || '\\'
|
50
|
+
elsif line.sub!(/\A([^\s\\'"]+)/, '') then
|
51
|
+
snippet = $1
|
52
|
+
else
|
53
|
+
line.lstrip!
|
54
|
+
break
|
55
|
+
end
|
56
|
+
field.concat(snippet)
|
57
|
+
end
|
58
|
+
words.push(field)
|
59
|
+
end
|
60
|
+
words
|
61
|
+
end
|
62
|
+
|
63
|
+
alias shellwords shellsplit
|
64
|
+
|
65
|
+
module_function :shellsplit, :shellwords
|
66
|
+
|
67
|
+
class << self
|
68
|
+
alias split shellsplit
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# Escapes a string so that it can be safely used in a Bourne shell
|
73
|
+
# command line.
|
74
|
+
#
|
75
|
+
# Note that a resulted string should be used unquoted and is not
|
76
|
+
# intended for use in double quotes nor in single quotes.
|
77
|
+
#
|
78
|
+
# open("| grep #{Shellwords.escape(pattern)} file") { |pipe|
|
79
|
+
# # ...
|
80
|
+
# }
|
81
|
+
#
|
82
|
+
# +String#shellescape+ is a shorthand for this function.
|
83
|
+
#
|
84
|
+
# open("| grep #{pattern.shellescape} file") { |pipe|
|
85
|
+
# # ...
|
86
|
+
# }
|
87
|
+
#
|
88
|
+
def shellescape(str)
|
89
|
+
# An empty argument will be skipped, so return empty quotes.
|
90
|
+
return "''" if str.empty?
|
91
|
+
|
92
|
+
str = str.dup
|
93
|
+
|
94
|
+
# Process as a single byte sequence because not all shell
|
95
|
+
# implementations are multibyte aware.
|
96
|
+
str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1")
|
97
|
+
|
98
|
+
# A LF cannot be escaped with a backslash because a backslash + LF
|
99
|
+
# combo is regarded as line continuation and simply ignored.
|
100
|
+
str.gsub!(/\n/, "'\n'")
|
101
|
+
|
102
|
+
return str
|
103
|
+
end
|
104
|
+
|
105
|
+
module_function :shellescape
|
106
|
+
|
107
|
+
class << self
|
108
|
+
alias escape shellescape
|
109
|
+
end
|
110
|
+
|
111
|
+
#
|
112
|
+
# Builds a command line string from an argument list +array+ joining
|
113
|
+
# all elements escaped for Bourne shell and separated by a space.
|
114
|
+
#
|
115
|
+
# open('|' + Shellwords.join(['grep', pattern, *files])) { |pipe|
|
116
|
+
# # ...
|
117
|
+
# }
|
118
|
+
#
|
119
|
+
# +Array#shelljoin+ is a shorthand for this function.
|
120
|
+
#
|
121
|
+
# open('|' + ['grep', pattern, *files].shelljoin) { |pipe|
|
122
|
+
# # ...
|
123
|
+
# }
|
124
|
+
#
|
125
|
+
def shelljoin(array)
|
126
|
+
array.map { |arg| shellescape(arg) }.join(' ')
|
127
|
+
end
|
128
|
+
|
129
|
+
module_function :shelljoin
|
130
|
+
|
131
|
+
class << self
|
132
|
+
alias join shelljoin
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
class String
|
137
|
+
#
|
138
|
+
# call-seq:
|
139
|
+
# str.shellsplit => array
|
140
|
+
#
|
141
|
+
# Splits +str+ into an array of tokens in the same way the UNIX
|
142
|
+
# Bourne shell does. See +Shellwords::shellsplit+ for details.
|
143
|
+
#
|
144
|
+
def shellsplit
|
145
|
+
Shellwords.split(self)
|
146
|
+
end
|
147
|
+
|
148
|
+
#
|
149
|
+
# call-seq:
|
150
|
+
# str.shellescape => string
|
151
|
+
#
|
152
|
+
# Escapes +str+ so that it can be safely used in a Bourne shell
|
153
|
+
# command line. See +Shellwords::shellescape+ for details.
|
154
|
+
#
|
155
|
+
def shellescape
|
156
|
+
Shellwords.escape(self)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
class Array
|
161
|
+
#
|
162
|
+
# call-seq:
|
163
|
+
# array.shelljoin => string
|
164
|
+
#
|
165
|
+
# Builds a command line string from an argument list +array+ joining
|
166
|
+
# all elements escaped for Bourne shell and separated by a space.
|
167
|
+
# See +Shellwords::shelljoin+ for details.
|
168
|
+
#
|
169
|
+
def shelljoin
|
170
|
+
Shellwords.join(self)
|
171
|
+
end
|
172
|
+
end
|
data/lib/shellwords.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "rubysl/shellwords"
|
data/rubysl-shellwords.gemspec
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
#
|
2
|
-
require
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubysl/shellwords/version'
|
3
3
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubysl-shellwords"
|
6
|
+
spec.version = RubySL::Shellwords::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Ruby standard library shellwords.}
|
10
|
+
spec.summary = %q{Ruby standard library shellwords.}
|
11
|
+
spec.homepage = "https://github.com/rubysl/rubysl-shellwords"
|
12
|
+
spec.license = "BSD"
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = RubySL::Shellwords::VERSION
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
gem.add_development_dependency "mspec", "~> 1.5"
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
+
spec.add_development_dependency "mspec", "~> 1.5"
|
22
22
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
include Shellwords
|
3
|
+
|
4
|
+
describe "Shellwords#shellwords" do
|
5
|
+
it "honors quoted strings" do
|
6
|
+
shellwords('a "b b" a').should == ['a', 'b b', 'a']
|
7
|
+
end
|
8
|
+
|
9
|
+
it "honors escaped double quotes" do
|
10
|
+
shellwords('a "\"b\" c" d').should == ['a', '"b" c', 'd']
|
11
|
+
end
|
12
|
+
|
13
|
+
it "honors escaped single quotes" do
|
14
|
+
shellwords("a \"'b' c\" d").should == ['a', "'b' c", 'd']
|
15
|
+
end
|
16
|
+
|
17
|
+
it "honors escaped spaces" do
|
18
|
+
shellwords('a b\ c d').should == ['a', 'b c', 'd']
|
19
|
+
end
|
20
|
+
|
21
|
+
it "raises ArgumentError when double quoted strings are misquoted" do
|
22
|
+
lambda { shellwords('a "b c d e') }.should raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "raises ArgumentError when single quoted strings are misquoted" do
|
26
|
+
lambda { shellwords("a 'b c d e") }.should raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,118 +1,99 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubysl-shellwords
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 0.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Brian Shirai
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
date: 2013-08-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
22
21
|
prerelease: false
|
23
|
-
|
24
|
-
|
25
|
-
requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
26
24
|
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
|
30
|
-
- 1
|
31
|
-
- 0
|
32
|
-
version: "1.0"
|
33
|
-
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
36
28
|
name: rake
|
37
|
-
|
38
|
-
|
39
|
-
none: false
|
40
|
-
requirements:
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
41
31
|
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 10
|
46
|
-
- 0
|
47
|
-
version: "10.0"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
48
34
|
type: :development
|
49
|
-
version_requirements: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: mspec
|
52
35
|
prerelease: false
|
53
|
-
|
54
|
-
|
55
|
-
requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
56
38
|
- - ~>
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
63
48
|
type: :development
|
64
|
-
|
65
|
-
|
66
|
-
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
description: Ruby standard library shellwords.
|
56
|
+
email:
|
67
57
|
- brixen@gmail.com
|
68
58
|
executables: []
|
69
|
-
|
70
59
|
extensions: []
|
71
|
-
|
72
60
|
extra_rdoc_files: []
|
73
|
-
|
74
|
-
files:
|
61
|
+
files:
|
75
62
|
- .gitignore
|
63
|
+
- .travis.yml
|
76
64
|
- Gemfile
|
77
65
|
- LICENSE
|
78
66
|
- README.md
|
79
67
|
- Rakefile
|
80
|
-
- lib/rubysl
|
81
|
-
- lib/rubysl
|
68
|
+
- lib/rubysl/shellwords.rb
|
69
|
+
- lib/rubysl/shellwords/shellwords.rb
|
70
|
+
- lib/rubysl/shellwords/version.rb
|
71
|
+
- lib/shellwords.rb
|
82
72
|
- rubysl-shellwords.gemspec
|
83
|
-
|
84
|
-
|
85
|
-
|
73
|
+
- spec/shellwords_spec.rb
|
74
|
+
homepage: https://github.com/rubysl/rubysl-shellwords
|
75
|
+
licenses:
|
76
|
+
- BSD
|
77
|
+
metadata: {}
|
86
78
|
post_install_message:
|
87
79
|
rdoc_options: []
|
88
|
-
|
89
|
-
require_paths:
|
80
|
+
require_paths:
|
90
81
|
- lib
|
91
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
none: false
|
102
|
-
requirements:
|
103
|
-
- - ">="
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
hash: 2002549777813010636
|
106
|
-
segments:
|
107
|
-
- 0
|
108
|
-
version: "0"
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
109
92
|
requirements: []
|
110
|
-
|
111
93
|
rubyforge_project:
|
112
|
-
rubygems_version:
|
94
|
+
rubygems_version: 2.0.7
|
113
95
|
signing_key:
|
114
|
-
specification_version:
|
115
|
-
summary: Ruby
|
116
|
-
test_files:
|
117
|
-
|
118
|
-
has_rdoc:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Ruby standard library shellwords.
|
98
|
+
test_files:
|
99
|
+
- spec/shellwords_spec.rb
|