diff --git a/index.js b/index.js index e3c0d0f..00c27bf 100644 --- a/index.js +++ b/index.js @@ -3,9 +3,18 @@ import isGit from 'is-git-repository'; import { platform } from 'os'; import makepath from 'path'; import pathIsAbsolute from 'path-is-absolute'; +import shellescape from 'shell-escape'; const cwd = process.cwd(); +// Escape bad arguments +var escapeShell = function(cmd) { + if(cmd !== undefined){ + var arg = cmd.toString().split(" "); + return shellescape(arg); + } +} + const taggedGitCommits = ({ path, lookBehind, local, remote } = {}) => { let getCommits; @@ -15,6 +24,12 @@ const taggedGitCommits = ({ path, lookBehind, local, remote } = {}) => { const thisLocal = local === undefined ? true : local; const thisRemote = remote || 'origin'; const taggedCommits = []; + + // escaping bad shell args + thisPath = escapeShell(thisPath); + thisLookBehind = escapeShell(thisLookBehind); + thisLocal = escapeShell(thisLocal); + thisRemote = escapeShell(thisRemote); if (!isGit(thisPath)) { return []; diff --git a/package.json b/package.json index 485491e..4eacde6 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,8 @@ "execa": "^0.6.1", "fs-extra": "^3.0.1", "is-git-repository": "^1.1.1", - "path-is-absolute": "^1.0.1" + "path-is-absolute": "^1.0.1", + "shell-escape": "^0.2.0" }, "devDependencies": { "ava": "^0.18.2",