Stop splitting string commands on spaces in `exec`

Offen
#1,525 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 4 Tagen

@Mario-Mohar arbeitet bereits daran.

Seit 30.10.2026.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
55/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
docker, node.js, typescript
Bereich
backend, testing

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.
Vorherrschende Sprache
TypeScript
Sterne
2.7k
Forks
290
Ø Merge
4 T. 1 Std.
Gemergte PRs (30 T.)
22

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus testcontainers/testcontainers-node

Alle Issues in testcontainers/testcontainers-node

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.