Skip to content

Commit

Permalink
Properly quote command and argument for echo (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey authored Nov 26, 2018
1 parent 4de55d6 commit 14f1f21
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const chokidar = require('chokidar')
const arrify = require('arrify')
const { Deque } = require('@blakeembrey/deque')

const ECHO_CMD = `${process.execPath} ${resolve(__dirname, 'echo.js')}`
const ECHO_JS_PATH = resolve(__dirname, 'echo.js')
const ECHO_CMD = `${quote(process.execPath)} ${quote(ECHO_JS_PATH)}`

/**
* Export `onchange` function.
Expand Down Expand Up @@ -211,3 +212,10 @@ function outpipeTemplate (str) {
function exitmsg (code, signal) {
return code == null ? `exited with ${signal}` : `completed with ${code}`
}

/**
* Quote value for `exec`.
*/
function quote (str) {
return `'${str.replace(/'/g, "'\\''")}'`
}

0 comments on commit 14f1f21

Please sign in to comment.