ukiryu 0.1.6 → 0.1.7
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.
- checksums.yaml +4 -4
- data/lib/ukiryu/shell/powershell.rb +33 -2
- data/lib/ukiryu/version.rb +1 -1
- data/spec/ukiryu/shell/powershell_spec.rb +67 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b1cb7b872cb1bf64055841e0a8d278b1b57f97fe7bf2133a52067eeee8d51f9f
|
|
4
|
+
data.tar.gz: 200175ef0a1a88d193396363b8a6335a01ed8d3a91863d660b25767f86abab4a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b3a7ed29941fab82a1b5b055a246234245ae7ba7c50d6d779b107b5a64d567bdbc4a71b3480182aab57831ab0a3119c36e71fa273157ace8b6f316c6ea11467b
|
|
7
|
+
data.tar.gz: 03f7e09b741cb05f4a0188511326438671d48a54444441d8abb2d15dfb969afd2ca6eb435dc1b9f0c893bb5015cf8c44b5131cf778c2e8d06062d6ba22e3aafc
|
|
@@ -50,6 +50,27 @@ module Ukiryu
|
|
|
50
50
|
string.to_s.gsub(/[`"$]/) { "`#{::Regexp.last_match(0)}" }
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
# Check if a string needs quoting for PowerShell
|
|
54
|
+
# Overrides base class to add PowerShell-specific handling
|
|
55
|
+
#
|
|
56
|
+
# In PowerShell, arguments starting with - are interpreted as PowerShell
|
|
57
|
+
# parameters when passed to the call operator (&). This causes the prefix
|
|
58
|
+
# to be stripped (e.g., -sDEVICE=pdfwrite becomes =pdfwrite).
|
|
59
|
+
# To prevent this, we must quote all arguments starting with -.
|
|
60
|
+
#
|
|
61
|
+
# @param string [String] the string to check
|
|
62
|
+
# @return [Boolean] true if quoting is needed
|
|
63
|
+
def needs_quoting?(string)
|
|
64
|
+
str = string.to_s
|
|
65
|
+
# Call super for base checks (empty, whitespace, special chars)
|
|
66
|
+
return true if super(string)
|
|
67
|
+
# PowerShell-specific: arguments starting with - must be quoted
|
|
68
|
+
# to prevent PowerShell's parameter binder from stripping the prefix
|
|
69
|
+
return true if str.start_with?('-')
|
|
70
|
+
|
|
71
|
+
false
|
|
72
|
+
end
|
|
73
|
+
|
|
53
74
|
# Quote an argument for PowerShell
|
|
54
75
|
# Uses single quotes for literal strings
|
|
55
76
|
# Uses double quotes for executable paths (works in both cmd.exe and PowerShell)
|
|
@@ -156,7 +177,12 @@ module Ukiryu
|
|
|
156
177
|
# Use double quotes for PowerShell -Command (works better than single quotes)
|
|
157
178
|
exe_quoted = %("#{escape(executable)}")
|
|
158
179
|
|
|
159
|
-
# Quote each argument
|
|
180
|
+
# Quote each argument based on needs_quoting?
|
|
181
|
+
# Note: We do NOT add special handling for -Command/-File here because
|
|
182
|
+
# this method builds a PowerShell script string (using the & call operator),
|
|
183
|
+
# not a command line for the shell. The -Command/-File handling in join()
|
|
184
|
+
# is for when building command lines where PowerShell's parameter binder
|
|
185
|
+
# would interpret -prefixed arguments.
|
|
160
186
|
args_quoted = args.map do |a|
|
|
161
187
|
if needs_quoting?(a)
|
|
162
188
|
%("#{escape(a)}")
|
|
@@ -219,7 +245,12 @@ module Ukiryu
|
|
|
219
245
|
# Use double quotes for PowerShell -Command (works better than single quotes)
|
|
220
246
|
exe_quoted = %("#{escape(executable)}")
|
|
221
247
|
|
|
222
|
-
# Quote each argument
|
|
248
|
+
# Quote each argument based on needs_quoting?
|
|
249
|
+
# Note: We do NOT add special handling for -Command/-File here because
|
|
250
|
+
# this method builds a PowerShell script string (using the & call operator),
|
|
251
|
+
# not a command line for the shell. The -Command/-File handling in join()
|
|
252
|
+
# is for when building command lines where PowerShell's parameter binder
|
|
253
|
+
# would interpret -prefixed arguments.
|
|
223
254
|
args_quoted = args.map do |a|
|
|
224
255
|
if needs_quoting?(a)
|
|
225
256
|
%("#{escape(a)}")
|
data/lib/ukiryu/version.rb
CHANGED
|
@@ -207,6 +207,73 @@ RSpec.describe Ukiryu::Shell::PowerShell do
|
|
|
207
207
|
expect(result).to eq('echo \'``malicious``\'')
|
|
208
208
|
end
|
|
209
209
|
end
|
|
210
|
+
|
|
211
|
+
context 'quoting dash-prefixed arguments' do
|
|
212
|
+
it 'quotes arguments starting with dash' do
|
|
213
|
+
result = shell.join('gswin64c.exe', '-sDEVICE=pdfwrite', 'input.eps')
|
|
214
|
+
expect(result).to eq('gswin64c.exe \'-sDEVICE=pdfwrite\' input.eps')
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
it 'quotes multiple dash-prefixed arguments' do
|
|
218
|
+
result = shell.join('gswin64c.exe', '-sDEVICE=pdfwrite',
|
|
219
|
+
'-sOutputFile=output.pdf', '-dBATCH', 'input.eps')
|
|
220
|
+
expect(result).to eq('gswin64c.exe \'-sDEVICE=pdfwrite\' ' \
|
|
221
|
+
'\'-sOutputFile=output.pdf\' \'-dBATCH\' input.eps')
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
it 'quotes ImageMagick-style options' do
|
|
225
|
+
result = shell.join('magick', 'input.png', '-resize', '50x50', 'output.png')
|
|
226
|
+
expect(result).to eq('magick input.png \'-resize\' 50x50 output.png')
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
it 'still handles -Command specially (not quoted, next arg not quoted)' do
|
|
230
|
+
result = shell.join('powershell', '-Command', 'Write-Host hello')
|
|
231
|
+
expect(result).to eq('powershell -Command Write-Host hello')
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
it 'still handles -File specially (not quoted, next arg not quoted)' do
|
|
235
|
+
result = shell.join('powershell', '-File', 'script.ps1')
|
|
236
|
+
expect(result).to eq('powershell -File script.ps1')
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
it 'quotes dash-prefixed args after -Command script' do
|
|
240
|
+
result = shell.join('powershell', '-Command', 'script.ps1', '-SomeFlag')
|
|
241
|
+
expect(result).to eq('powershell -Command script.ps1 \'-SomeFlag\'')
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
describe '#needs_quoting?' do
|
|
247
|
+
it 'returns true for empty strings' do
|
|
248
|
+
expect(shell.needs_quoting?('')).to be true
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
it 'returns true for strings with whitespace' do
|
|
252
|
+
expect(shell.needs_quoting?('hello world')).to be true
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
it 'returns true for strings with special characters' do
|
|
256
|
+
expect(shell.needs_quoting?('hello;world')).to be true
|
|
257
|
+
expect(shell.needs_quoting?('hello&world')).to be true
|
|
258
|
+
expect(shell.needs_quoting?('hello|world')).to be true
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
it 'returns true for strings starting with dash' do
|
|
262
|
+
expect(shell.needs_quoting?('-sDEVICE=pdfwrite')).to be true
|
|
263
|
+
expect(shell.needs_quoting?('-resize')).to be true
|
|
264
|
+
expect(shell.needs_quoting?('-dBATCH')).to be true
|
|
265
|
+
expect(shell.needs_quoting?('-')).to be true
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
it 'returns false for simple strings' do
|
|
269
|
+
expect(shell.needs_quoting?('hello')).to be false
|
|
270
|
+
expect(shell.needs_quoting?('input.eps')).to be false
|
|
271
|
+
expect(shell.needs_quoting?('output.pdf')).to be false
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
it 'returns false for strings with dollar sign (PowerShell treats as literal)' do
|
|
275
|
+
expect(shell.needs_quoting?('$VAR')).to be false
|
|
276
|
+
end
|
|
210
277
|
end
|
|
211
278
|
|
|
212
279
|
describe '#format_path' do
|