Stop splitting string commands on spaces in `exec`

Ouverte
#1,525 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 4 jours

@Mario-Mohar y travaille déjà.

Depuis le 30/10/2026.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
55/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
docker, node.js, typescript
Domaine
backend, testing

Piste de recherche

Start at exec in packages/testcontainers/src/generic/started-generic.ts and compare how its string and array forms build arguments. Then inspect the Redis and Valkey call sites named in the issue, and coordinate the string overload deprecation with #1518. Done means commands with spaces are passed as intended, both module calls use the array form, and the relevant tests cover the behavior.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug minor

What happens

exec accepts string | string[]. The string form is turned into arguments with command.split(" "), so quoting is not honoured and any argument containing a space is broken up.

await container.exec('sh -c "echo hello world"');
// exitCode: 2
// stderr: hello: line 1: syntax error: unterminated quoted string

await container.exec(["sh", "-c", "echo hello world"]);
// exitCode: 0
// stdout: hello world

Two modules use the string form with an interpolated value:

  • packages/modules/redis/src/redis-container.ts: container.exec(`/tmp/import.sh ${this.password}`)
  • packages/modules/valkey/src/valkey-container.ts: container.exec(`/tmp/import.sh ${this.password || ""}`)

A password containing a space is split into separate arguments (from reading the code).

Expected

A command is never split on spaces. Either the string form goes away, or it is parsed with shell quoting rules.

Where

exec in packages/testcontainers/src/generic-container/started-generic-container.ts.

Notes

  • Java (execInContainer(String... command)) and Go (Exec(ctx, cmd []string, ...)) accept only an argument list.
  • The docs only show the array form.
  • Switch the redis and valkey calls to the array form either way.
  • Semver: labelled minor for deprecating the string overload, with removal in a later major.
  • Reproduced on main (aa60a746, 12.2.0) with Docker 29.6.1.

Dependencies

  • Nothing blocks this. It can start now.
  • Coordinate with #1518: for how the string overload is deprecated.
Langage dominant
TypeScript
Étoiles
2.7k
Forks
290
Merge moyen
4 j 1 h
PR mergées (30 j)
22

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de testcontainers/testcontainers-node

Toutes les issues de testcontainers/testcontainers-node

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.