Comparing version 0.1.26 to 0.1.27
var removeParens = require('./remove-parens'), | ||
substituteVars = require('./substitute-vars'), | ||
unescapeAndQuote = require('./unescape-and-quote'); | ||
unescapeAndQuote = require('./unescape-and-quote'), | ||
stripSemicolon = require('./strip-semicolon'); | ||
module.exports = function (context) { | ||
@@ -15,3 +16,3 @@ var executableExists = require('./executable-exists')(context), | ||
if (builtIn) return builtIn; | ||
else if (executableExists(removeParens(v.match(/^\s*(\S+)/)[1]))) return substituteTilde(substituteVars(unescapeAndQuote(substituteAliases(v)).replace(/'/g, '\\\'').replace(/^\s*(.*?);?$/g, 'execSync(\'$1\');'))); | ||
else if (executableExists(removeParens(stripSemicolon(v.match(/^\s*(\S+)/)[1]))) || context.cmds.alias.aliases[stripSemicolon(v.match(/^\s*(\S+)/)[1])]) return substituteTilde(substituteVars(unescapeAndQuote(substituteAliases(v)).replace(/'/g, '\\\'').replace(/^\s*(.*?);?$/g, 'execSync(\'$1\');'))); | ||
return v; | ||
@@ -18,0 +19,0 @@ } |
module.exports = function (context) { | ||
var aliases = context.cmds.alias.aliases; | ||
return function substituteAliases (cmd) { | ||
Object.keys(aliases).forEach(function (v) { | ||
cmd = cmd.replace(RegExp('^(\\s*)' + v, 'g'), '$1' + aliases[v]); | ||
}); | ||
var j = 0, start = 0; | ||
for (var i in aliases) { | ||
j = 0, start = 0, found = false; | ||
while (cmd[j]) { | ||
if (cmd[j + start] === i[start]) { | ||
start++; | ||
if (start === i.length) { | ||
if (/\s/.test(cmd[j + start]) || cmd[j + start] === undefined || cmd[j + start] === ';') { | ||
cmd = cmd.substr(0, j) + aliases[i] + cmd.substr(j + start); | ||
j += start + aliases[i].length; | ||
start = 0; | ||
found = true; | ||
} | ||
} | ||
continue; | ||
} else if (start) { | ||
j += start; | ||
start = 0; | ||
} | ||
j++; | ||
} | ||
if (found) break; | ||
} | ||
return cmd; | ||
} | ||
} |
{ | ||
"name": "jsh", | ||
"version": "0.1.26", | ||
"version": "0.1.27", | ||
"description": "The JavaScript shell interpreter.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,3 +18,4 @@ var vm = require('vm'), | ||
sandbox.cmds.alias.aliases = { | ||
ls: 'ls --color=auto' | ||
ls: 'ls --color=auto', | ||
lsa: 'ls -a' | ||
}; | ||
@@ -36,2 +37,3 @@ | ||
escapeSpaces = require('../lib/util/escape-spaces'), | ||
stripSemicolon = require('../lib/util/strip-semicolon'), | ||
breakUpCommand = require('../lib/util/break-up-command'), | ||
@@ -98,2 +100,6 @@ unescapeAndQuote = require('../lib/util/unescape-and-quote'), | ||
}); | ||
it('should strip semicolons', function () { | ||
expect(stripSemicolon('lsa;')).to.equal('lsa'); | ||
expect(stripSemicolon('ls')).to.equal('ls'); | ||
}); | ||
}); | ||
@@ -112,2 +118,4 @@ describe('command rewriter', function () { | ||
expect(substituteAliases('ls')).to.equal('ls --color=auto'); | ||
expect(substituteAliases('lsa')).to.equal('ls -a'); | ||
expect(substituteAliases('ls;')).to.equal('ls --color=auto;'); | ||
}); | ||
@@ -114,0 +122,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138608
56
2592