Skip to content

Commit

Permalink
process/task/terminal: refactor escaping/quoting
Browse files Browse the repository at this point in the history
Add utility functions in `@theia/process/lib/common` to escape common
shells' arguments. Refactored terminal processes to not handle shell
escaping anymore, it is the caller's responsability to provide the
escaped spawn options.

Escaping is now done for DAP's `runInTerminal` requests.

Signed-off-by: Paul Maréchal <paul.marechal@ericsson.com>
  • Loading branch information
paul-marechal committed Jan 8, 2020
1 parent 8ddf4b6 commit 727b276
Show file tree
Hide file tree
Showing 27 changed files with 1,358 additions and 350 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@types/webdriverio": "^4.7.0",
"chai": "^4.1.0",
"chai-string": "^1.4.0",
"colors": "^1.4.0",
"concurrently": "^3.5.0",
"electron-mocha": "~3.5.0",
"ignore-styles": "^5.0.1",
Expand Down
7 changes: 4 additions & 3 deletions packages/debug/src/browser/debug-session-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ export class DefaultDebugSessionFactory implements DebugSessionFactory {
resolve(channel);
}, { reconnecting: false })
),
this.getTraceOutputChannel());

this.getTraceOutputChannel()
);
return new DebugSession(
sessionId,
options,
Expand All @@ -134,7 +134,8 @@ export class DefaultDebugSessionFactory implements DebugSessionFactory {
this.breakpoints,
this.labelProvider,
this.messages,
this.fileSystem);
this.fileSystem,
);
}

protected getTraceOutputChannel(): OutputChannel | undefined {
Expand Down
5 changes: 3 additions & 2 deletions packages/debug/src/browser/debug-session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,9 @@ export class DebugSession implements CompositeTreeElement {

protected async runInTerminal({ arguments: { title, cwd, args, env } }: DebugProtocol.RunInTerminalRequest): Promise<DebugProtocol.RunInTerminalResponse['body']> {
const terminal = await this.doCreateTerminal({ title, cwd, env });
terminal.sendText(args.join(' ') + '\n');
return { processId: await terminal.processId };
const { processId } = terminal;
await terminal.executeCommand({ cwd, args, env });
return { processId: await processId };
}

protected async doCreateTerminal(options: TerminalWidgetOptions): Promise<TerminalWidget> {
Expand Down
4 changes: 4 additions & 0 deletions packages/process/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"access": "public"
},
"theiaExtensions": [
{
"backend": "lib/common/process-common-module",
"frontend": "lib/common/process-common-module"
},
{
"backend": "lib/node/process-backend-module"
}
Expand Down
22 changes: 22 additions & 0 deletions packages/process/src/common/process-common-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/********************************************************************************
* Copyright (C) 2020 Ericsson and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { ContainerModule } from 'inversify';
import { ShellCommandBuilder } from './shell-command-builder';

export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(ShellCommandBuilder).toSelf().inSingletonScope();
});
Loading

0 comments on commit 727b276

Please sign in to comment.