Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsh

Package Overview
Dependencies
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsh - npm Package Compare versions

Comparing version 0.1.26 to 0.1.27

lib/util/strip-semicolon.js

5

lib/util/sandr.js
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 @@ }

26

lib/util/substitute-aliases.js
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 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc