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.

Changelog:

- Moved quoting types and functions from
  `process/lib/node/termina-process.ts` to
  `process/lib/common/shell-quoting.ts`.

- Added a `ShellCommandBuilder` component, used to build commands for
  evaluation in a shell (as if someone was typing manually).

- `TerminalProcess` no longer supports running things in a shell as part
  of its options. Execution in a shell must be encoded in the spawn
  options by the caller. You can use `createShellCommandLine` to process
  arguments.

Signed-off-by: Paul Maréchal <[email protected]>
  • Loading branch information
paul-marechal committed Mar 24, 2020
1 parent 27d7204 commit ee68ad8
Show file tree
Hide file tree
Showing 29 changed files with 1,568 additions and 355 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
## v0.17.0

- [preferences] add a new preference to silence notifications [#7195](https://github.com/eclipse-theia/theia/pull/7195)
- [core] fixed keybindings for special Numpad keys in editors [#7315]
- [core] fixed keybindings for special Numpad keys in editors [#7315]

Breaking changes:

- [scm][git] the History view (GitHistoryWidget) has moved from the git package to a new package, scm-extra, and
renamed to ScmHistoryWidget. GitNavigableListWidget has also moved.
CSS classes have been moved renamed accordingly. [6381](https://github.com/eclipse-theia/theia/pull/6381)
- [process] `TerminalProcess` doesn't handle shell quoting, the shell process arguments must be prepared from the caller. Removed all methods related to shell escaping inside this class. You should use functions located in `@theia/process/lib/common/shell-quoting.ts` in order to process arguments for shells.
- [process/terminal] Moved shell escaping utilities into `@theia/process/lib/common/shell-quoting` and `@theia/process/lib/common/shell-command-builder` for creating shell inputs.

## v0.16.0

Expand Down Expand Up @@ -231,6 +233,7 @@ Breaking changes:
- One can resolve a current color value programmatically with `ColorRegistry.getCurrentColor`.
- One can load a new color theme:
- in the frontend module to enable it on startup

```ts
MonacoThemingService.register({
id: 'myDarkTheme',
Expand All @@ -242,7 +245,9 @@ Breaking changes:
}
});
```

- later from a file:

```ts
@inject(MonacoThemingService)
protected readonly monacoThemeService: MonacoThemingService;
Expand All @@ -254,6 +259,7 @@ Breaking changes:
uri: 'file:///absolute/path/to/my_theme.json'
});
```

- or install from a VS Code extension.
- One should not introduce css color variables anymore or hardcode colors in css.
- One can contribute new colors by implementing `ColorContribution` contribution point and calling `ColorRegistry.register`.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@typescript-eslint/eslint-plugin-tslint": "^2.16.0",
"@typescript-eslint/parser": "^2.16.0",
"chai-string": "^1.4.0",
"colors": "^1.4.0",
"concurrently": "^3.5.0",
"electron-mocha": "^8.2.0",
"eslint": "^6.8.0",
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 @@ -385,8 +385,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, useServerTitle: false });
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 ee68ad8

Please sign in to comment.