diff --git a/index.js b/index.js index b8eb645..e3be231 100644 --- a/index.js +++ b/index.js @@ -3,9 +3,17 @@ 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(); +var escapeShell = function(cmd) { + if(cmd !== undefined){ + var arg = cmd.toString().split(" "); + return shellescape(arg); + } +} + const getCommitRange = (options = {}) => { const { path, @@ -29,6 +37,11 @@ const getCommitRange = (options = {}) => { let getCommits; thisPath = pathIsAbsolute(thisPath) ? thisPath : makepath.join(cwd, thisPath); + + // escaping bad shell arguments + thisPath = escapeShell(thisPath); + thisFrom = escapeShell(thisFrom); + thisTo = escapeShell(thisTo); if (!isGit(thisPath)) { return []; diff --git a/package.json b/package.json index e205a2a..b72b345 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "execa": "^0.7.0", "is-git-repository": "^1.1.1", "os": "^0.1.1", - "path-is-absolute": "^1.0.1" + "path-is-absolute": "^1.0.1", + "shell-escape": "^0.2.0" }, "devDependencies": { "@babel/cli": "^7.8.4",