Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: improve quoting for run-script arguments #52

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions lib/run-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ var usage = require('./utils/usage')
var output = require('./utils/output.js')
var didYouMean = require('./utils/did-you-mean')
var isWindowsShell = require('./utils/is-windows-shell.js')
var puka = require('puka')
var sh = puka.sh
var unquoted = puka.unquoted

runScript.usage = usage(
'run-script',
Expand Down Expand Up @@ -166,20 +169,10 @@ function run (pkg, wd, cmd, args, cb) {
chain(cmds.map(function (c) {
// pass cli arguments after -- to script.
if (pkg.scripts[c] && c === cmd) {
pkg.scripts[c] = pkg.scripts[c] + joinArgs(args)
pkg.scripts[c] = sh`${unquoted(pkg.scripts[c])} ${args}`
}

// when running scripts explicitly, assume that they're trusted.
return [lifecycle, pkg, c, wd, { unsafePerm: true }]
}), cb)
}

// join arguments after '--' and pass them to script,
// handle special characters such as ', ", ' '.
function joinArgs (args) {
var joinedArgs = ''
args.forEach(function (arg) {
joinedArgs += ' "' + arg.replace(/"/g, '\\"') + '"'
})
return joinedArgs
}
18 changes: 18 additions & 0 deletions node_modules/puka/LICENSE.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading