Skip to content

Commit d629647

Browse files
authored
fix(shell-evaluator): treat cmd whose arg starts with ( as fn call MONGOSH-858 (#978)
If the argument to a shell command starts with `(`, we treat it as a function call, since that is probably the intended usage here.
1 parent a35c3f2 commit d629647

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/shell-evaluator/src/shell-evaluator.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ describe('ShellEvaluator', () => {
4444
expect(useSpy).to.have.been.calledWith('somedb');
4545
});
4646

47+
it('does not apply special handling for commands when the first argument starts with (', async() => {
48+
const originalEval = sinon.spy();
49+
await shellEvaluator.customEval(originalEval, 'use (somedb);', {}, '');
50+
expect(originalEval.firstCall.args[0]).to.include('somedb');
51+
expect(useSpy).to.have.callCount(0);
52+
});
53+
4754
it('forwards show commands', async() => {
4855
const dontCallEval = () => { throw new Error('unreachable'); };
4956
await shellEvaluator.customEval(dontCallEval, 'show dbs;', {}, '');

packages/shell-evaluator/src/shell-evaluator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ShellEvaluator<EvaluationResultType = ShellResult> {
3636
const { shellApi } = this.internalState;
3737
const argv = input.trim().replace(/;$/, '').split(/\s+/g);
3838
const cmd = argv.shift() as keyof typeof shellApi;
39-
if (shellApi[cmd]?.isDirectShellCommand) {
39+
if (shellApi[cmd]?.isDirectShellCommand && !(argv[0] ?? '').startsWith('(')) {
4040
return shellApi[cmd](...argv);
4141
}
4242

0 commit comments

Comments
 (0)