shellwords 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -1
  3. data/lib/shellwords.rb +31 -18
  4. metadata +4 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ccc635a3993667e34ee88b0e3122d3aa1f67776c36cc69fcc68288e85cfe6f2a
4
- data.tar.gz: b64c7a5c30cc77284e49fa4cc8663369e3d90cd32b782443f1b5a955346f533a
3
+ metadata.gz: d8acce9d3d49704b5ee680d427e238dd9c8cf736515dfd2ae113e6f1505230ee
4
+ data.tar.gz: 4e5403da79a04b28031106a07b496a3f583beebff8f34be18ec4984ffc3c5b2c
5
5
  SHA512:
6
- metadata.gz: 8b81ed293a4dd49fe6cf0be82b1ad0d98efdecc3a549c13451ac638fdf546e067c5a556677fc4a2d3601772e4a9a03fba62ce29b786127f473b9d1b936175b19
7
- data.tar.gz: 1d91518f6df2b52b629bad0b7659006376e6667a4c2dc5c406649a221c65fbeffd5087146ac4fa58f9af9789ecf8119ae86ba32467061c019a61d8b8486f24cd
6
+ metadata.gz: b8ec0e6f107495ee21caf2cdc3f9726999266d91b1226404e2028a0d1d9805af928938d34fdf9261a70ffa632bb48611de9e4b8286168cbf87ed85a3216cab89
7
+ data.tar.gz: ba4c005e4dc6fa74beeec4952bf017586a6a58e4799eb9b0a1b8ed586b85aacd7921b0346cccddde80658ea2aabd8629017d8980c29a81a332088989dbab9bb2
data/README.md CHANGED
@@ -38,7 +38,15 @@ argv #=> ["three", "blind", "mice"]
38
38
 
39
39
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
40
 
41
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+ To install this gem onto your local machine, run `bundle exec rake install`.
42
+
43
+ To release a new version, update `Shellwords::VERSION` in `lib/shellwords.rb`.
44
+ Push the release commit to `master` and wait for CI to pass. Then create and
45
+ push a matching `vX.Y.Z` tag on that commit. The [publish workflow] builds the
46
+ gem, publishes it to [RubyGems.org], and creates a GitHub release.
47
+
48
+ [publish workflow]: https://github.com/ruby/shellwords/actions/workflows/push_gem.yml
49
+ [RubyGems.org]: https://rubygems.org/gems/shellwords
42
50
 
43
51
  ## Contributing
44
52
 
data/lib/shellwords.rb CHANGED
@@ -40,11 +40,10 @@
40
40
  # # runs "cat -- special\\'s.txt"
41
41
  #
42
42
  # Note the '--'. Without it, cat(1) will treat the following argument
43
- # as a command line option if it starts with '-'. It is guaranteed
44
- # that Shellwords.escape converts a string to a form that a Bourne
45
- # shell will parse back to the original string, but it is the
46
- # programmer's responsibility to make sure that passing an arbitrary
47
- # argument to a command does no harm.
43
+ # as a command line option if it starts with '-'. When the string's encoding
44
+ # is compatible with how the shell parses command lines, Shellwords.escape
45
+ # preserves the original argument.
46
+ # The caller must still ensure that passing the argument to the command is safe.
48
47
  #
49
48
  # Shellwords also comes with a core extension for Array, Array#shelljoin.
50
49
  #
@@ -65,7 +64,7 @@
65
64
 
66
65
  module Shellwords
67
66
  # The version number string.
68
- VERSION = "0.2.2"
67
+ VERSION = "0.3.0"
69
68
 
70
69
  # Splits a string into an array of tokens in the same way the UNIX
71
70
  # Bourne shell does.
@@ -89,7 +88,7 @@ module Shellwords
89
88
  # argv #=> ["here", "are", "two words"]
90
89
  def shellsplit(line)
91
90
  words = []
92
- field = String.new
91
+ field = nil
93
92
  line.scan(/\G\s*(?>([^\0\s\\\'\"]+)|'([^\0\']*)'|"((?:[^\0\"\\]|\\[^\0])*)"|(\\[^\0]?)|(\S))(\s|\z)?/m) do
94
93
  |word, sq, dq, esc, garbage, sep|
95
94
  if garbage
@@ -105,10 +104,15 @@ module Shellwords
105
104
  # characters when considered special:
106
105
  #
107
106
  # $ ` " \ <newline>
108
- field << (word || sq || (dq && dq.gsub(/\\([$`"\\\n])/, '\\1')) || esc.gsub(/\\(.)/, '\\1'))
109
- if sep
107
+ #
108
+ # An unquoted line continuation alone does not start a word.
109
+ unless esc == "\\\n"
110
+ field ||= String.new
111
+ field << (word || sq || (dq && dq.gsub(/\\(?:([$`"\\])|\n)/, '\\1')) || esc.gsub(/\\(.)/, '\\1'))
112
+ end
113
+ if sep && field
110
114
  words << field
111
- field = String.new
115
+ field = nil
112
116
  end
113
117
  end
114
118
  words
@@ -123,8 +127,8 @@ module Shellwords
123
127
  end
124
128
 
125
129
  # Escapes a string so that it can be safely used in a Bourne shell
126
- # command line. +str+ can be a non-string object that responds to
127
- # +to_s+.
130
+ # command line (see {Encoding considerations}[rdoc-ref:Shellwords.shellescape@Encoding+considerations]).
131
+ # +str+ can be a non-string object that responds to +to_s+.
128
132
  #
129
133
  # +str+ must not contain NUL characters because of nature of +exec+
130
134
  # system call.
@@ -149,12 +153,20 @@ module Shellwords
149
153
  # }
150
154
  # }
151
155
  #
152
- # It is the caller's responsibility to encode the string in the right
153
- # encoding for the shell environment where this string is used.
156
+ # Returns an empty quoted String if +str+ has a length of zero.
154
157
  #
155
- # Multibyte characters are treated as multibyte characters, not as bytes.
158
+ # === Encoding considerations
156
159
  #
157
- # Returns an empty quoted String if +str+ has a length of zero.
160
+ # The caller must choose an encoding suited to the shell environment.
161
+ # Shellwords escapes the string character by character. Some shells parse
162
+ # command lines byte by byte, even in multibyte locales. With encodings
163
+ # such as GBK, Big5, and Shift_JIS, these shells may interpret shell
164
+ # metacharacters in the escaped result even when the string's encoding
165
+ # matches the shell's locale.
166
+ #
167
+ # For byte-oriented shells, use <tt>Shellwords.escape(str.b)</tt> to escape
168
+ # the string byte by byte, or bypass the shell by passing arguments directly
169
+ # to the command.
158
170
  def shellescape(str)
159
171
  str = str.to_s
160
172
 
@@ -189,7 +201,7 @@ module Shellwords
189
201
  # All elements are joined into a single string with fields separated by a
190
202
  # space, where each element is escaped for the Bourne shell and stringified
191
203
  # using +to_s+.
192
- # See also Shellwords.shellescape.
204
+ # See {Encoding considerations}[rdoc-ref:Shellwords.shellescape@Encoding+considerations].
193
205
  #
194
206
  # ary = ["There's", "a", "time", "and", "place", "for", "everything"]
195
207
  # argv = Shellwords.join(ary)
@@ -212,6 +224,7 @@ module Shellwords
212
224
  module_function :shelljoin
213
225
 
214
226
  class << self
227
+ # See {Encoding considerations}[rdoc-ref:Shellwords.shellescape@Encoding+considerations].
215
228
  alias join shelljoin
216
229
  end
217
230
  end
@@ -232,7 +245,7 @@ class String
232
245
  # str.shellescape => string
233
246
  #
234
247
  # Escapes +str+ so that it can be safely used in a Bourne shell
235
- # command line.
248
+ # command line (see {Encoding considerations}[rdoc-ref:Shellwords.shellescape@Encoding+considerations]).
236
249
  #
237
250
  # See Shellwords.shellescape for details.
238
251
  def shellescape
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shellwords
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akinori MUSHA
8
- autorequire:
9
- bindir: exe
8
+ bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Manipulates strings with word parsing rules of UNIX Bourne shell.
14
13
  email:
@@ -34,7 +33,6 @@ licenses:
34
33
  metadata:
35
34
  homepage_uri: https://github.com/ruby/shellwords
36
35
  source_code_uri: https://github.com/ruby/shellwords
37
- post_install_message:
38
36
  rdoc_options: []
39
37
  require_paths:
40
38
  - lib
@@ -49,8 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
47
  - !ruby/object:Gem::Version
50
48
  version: '0'
51
49
  requirements: []
52
- rubygems_version: 3.5.11
53
- signing_key:
50
+ rubygems_version: 4.0.20
54
51
  specification_version: 4
55
52
  summary: Manipulates strings with word parsing rules of UNIX Bourne shell.
56
53
  test_files: []