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 9, 2020
1 parent 2ef80c0 commit bc4ca6e
Show file tree
Hide file tree
Showing 28 changed files with 1,495 additions and 460 deletions.
221 changes: 111 additions & 110 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,95 +1,96 @@
sudo: required
language: node_js
node_js: '10'
node_js: "10"
git:
depth: 1
cache:
yarn: true
directories:
# All directories need to be listed here, because Travis does not support globs.
# Auto generated by scripts/prepare-travis
# start_cache_directories
- /tmp/vscode-ripgrep-cache-1.5.7
- dev-packages/application-manager/node_modules
- dev-packages/application-package/node_modules
- dev-packages/electron/node_modules
- examples/api-samples/node_modules
- examples/browser/node_modules
- examples/electron/node_modules
- node_modules
- packages/callhierarchy/node_modules
- packages/console/node_modules
- packages/core/node_modules
- packages/debug-nodejs/node_modules
- packages/debug/node_modules
- packages/editor-preview/node_modules
- packages/editor/node_modules
- packages/editorconfig/node_modules
- packages/extension-manager/node_modules
- packages/file-search/node_modules
- packages/filesystem/node_modules
- packages/getting-started/node_modules
- packages/git/node_modules
- packages/java-debug/node_modules
- packages/java/node_modules
- packages/json/node_modules
- packages/keymaps/node_modules
- packages/languages/node_modules
- packages/markers/node_modules
- packages/merge-conflicts/node_modules
- packages/messages/node_modules
- packages/metrics/node_modules
- packages/mini-browser/node_modules
- packages/monaco/node_modules
- packages/navigator/node_modules
- packages/outline-view/node_modules
- packages/output/node_modules
- packages/plugin-dev/node_modules
- packages/plugin-ext-vscode/node_modules
- packages/plugin-ext/node_modules
- packages/plugin-metrics/node_modules
- packages/plugin/node_modules
- packages/preferences/node_modules
- packages/preview/node_modules
- packages/process/node_modules
- packages/python/node_modules
- packages/scm/node_modules
- packages/search-in-workspace/node_modules
- packages/task/node_modules
- packages/terminal/node_modules
- packages/textmate-grammars/node_modules
- packages/tslint/node_modules
- packages/typehierarchy/node_modules
- packages/typescript/node_modules
- packages/userstorage/node_modules
- packages/variable-resolver/node_modules
- packages/workspace/node_modules
# end_cache_directories
- packages/java-debug/download
- packages/debug-nodejs/download
# All directories need to be listed here, because Travis does not support globs.
# Auto generated by scripts/prepare-travis
# start_cache_directories
- /tmp/vscode-ripgrep-cache-1.5.7
- dev-packages/application-manager/node_modules
- dev-packages/application-package/node_modules
- dev-packages/electron/node_modules
- examples/api-samples/node_modules
- examples/browser/node_modules
- examples/electron/node_modules
- node_modules
- packages/callhierarchy/node_modules
- packages/console/node_modules
- packages/core/node_modules
- packages/debug-nodejs/node_modules
- packages/debug/node_modules
- packages/editor-preview/node_modules
- packages/editor/node_modules
- packages/editorconfig/node_modules
- packages/extension-manager/node_modules
- packages/file-search/node_modules
- packages/filesystem/node_modules
- packages/getting-started/node_modules
- packages/git/node_modules
- packages/java-debug/node_modules
- packages/java/node_modules
- packages/json/node_modules
- packages/keymaps/node_modules
- packages/languages/node_modules
- packages/markers/node_modules
- packages/merge-conflicts/node_modules
- packages/messages/node_modules
- packages/metrics/node_modules
- packages/mini-browser/node_modules
- packages/monaco/node_modules
- packages/navigator/node_modules
- packages/outline-view/node_modules
- packages/output/node_modules
- packages/plugin-dev/node_modules
- packages/plugin-ext-vscode/node_modules
- packages/plugin-ext/node_modules
- packages/plugin-metrics/node_modules
- packages/plugin/node_modules
- packages/preferences/node_modules
- packages/preview/node_modules
- packages/process/node_modules
- packages/python/node_modules
- packages/scm/node_modules
- packages/search-in-workspace/node_modules
- packages/task/node_modules
- packages/terminal/node_modules
- packages/textmate-grammars/node_modules
- packages/tslint/node_modules
- packages/typehierarchy/node_modules
- packages/typescript/node_modules
- packages/userstorage/node_modules
- packages/variable-resolver/node_modules
- packages/workspace/node_modules
# end_cache_directories
- packages/java-debug/download
- packages/debug-nodejs/download
before_cache:
# Runs before the cache is updated, after successful CI
- rm -f node_modules/@theia/electron/post-install.log
- rm -rf node_modules/@theia/electron/download
- rm -rf node_modules/electron
branches:
only:
- master
- master
env:
global:
- CXX=g++-4.8
- NODE_OPTIONS="--max_old_space_size=4096"
- THEIA_TEST_DEBUG=1
addons:
apt:
update: true
sources:
- ubuntu-toolchain-r-test
- ubuntu-toolchain-r-test
packages:
- g++-4.8
- libsecret-1-dev
- xvfb
- libx11-dev
- libxkbfile-dev
- g++-4.8
- libsecret-1-dev
- xvfb
- libx11-dev
- libxkbfile-dev
chrome: stable
jdk:
- oraclejdk9
Expand All @@ -115,50 +116,50 @@ script:
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/c42ddc125fe6bbfccb48
- https://webhooks.gitter.im/e/c42ddc125fe6bbfccb48
on_success: change
on_failure: always
on_start: never
jobs:
fast_finish: true
include:
- stage: test
os: linux
- os: osx
env: CXX=c++
before_script: skip
script:
- travis_retry yarn test:theia
- os: windows
env:
- CXX=c++
- YARN_GPG=no
before_script: skip
script:
- travis_retry yarn test:theia
- stage: deploy
if: NOT type IN (cron, pull_request)
os: linux
before_script: skip
script: skip
install: skip
before_deploy:
- |
if ! [ "$BEFORE_DEPLOY_RUN" ]; then
export BEFORE_DEPLOY_RUN=1
printf "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}\n" >> ~/.npmrc
THEIA_SKIP_NPM_PREPARE=1 yarn install --skip-integrity-check # fix cache we meddled-with
yarn run docs
fi
deploy:
- provider: script
script: yarn run publish:next
on:
branch: master
skip_cleanup: true
- provider: pages
skip_cleanup: true
github-token: $GITHUB_TOKEN
local-dir: gh-pages
on:
branch: master
- stage: test
os: linux
- os: osx
env: CXX=c++
before_script: skip
script:
- travis_retry yarn test:theia
- os: windows
env:
- CXX=c++
- YARN_GPG=no
before_script: skip
script:
- travis_retry yarn test:theia
- stage: deploy
if: NOT type IN (cron, pull_request)
os: linux
before_script: skip
script: skip
install: skip
before_deploy:
- |
if ! [ "$BEFORE_DEPLOY_RUN" ]; then
export BEFORE_DEPLOY_RUN=1
printf "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}\n" >> ~/.npmrc
THEIA_SKIP_NPM_PREPARE=1 yarn install --skip-integrity-check # fix cache we meddled-with
yarn run docs
fi
deploy:
- provider: script
script: yarn run publish:next
on:
branch: master
skip_cleanup: true
- provider: pages
skip_cleanup: true
github-token: $GITHUB_TOKEN
local-dir: gh-pages
on:
branch: master
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 bc4ca6e

Please sign in to comment.