Skip to content

fix: PortCommand parser handles single-port query format#232

Merged
joshrotenberg merged 1 commit intomainfrom
fix/port-command-parser
Jan 6, 2026
Merged

fix: PortCommand parser handles single-port query format#232
joshrotenberg merged 1 commit intomainfrom
fix/port-command-parser

Conversation

@joshrotenberg
Copy link
Copy Markdown
Owner

Summary

Fixes the PortCommand parser to handle the simpler output format returned when querying a specific port.

Fixes #231

Problem

When querying a specific port with docker port <container> <port>, Docker returns a simpler format:

0.0.0.0:40998
[::]:40998

Instead of the full format returned when listing all ports:

6379/tcp -> 0.0.0.0:40998
6379/tcp -> [::]:40998

The parser only handled the full format, causing host_port() in ContainerGuard to fail.

Solution

Updated parse_port_mappings() to accept an optional queried_port parameter. When the simple format is detected and queried_port is provided, the container port is inferred from the queried port.

Changes

  • src/command/port.rs: Updated parser to handle both formats
  • examples/testing_utilities.rs: Restored host_port() test now that the bug is fixed

Testing

  • Added unit tests for the new parsing logic
  • All 768 unit tests pass
  • All 10 example tests pass including host_port() verification

When querying a specific port with `docker port <container> <port>`,
Docker returns a simpler format without the container port prefix:
  0.0.0.0:8080
  [::]:8080

Instead of the full format returned when listing all ports:
  80/tcp -> 0.0.0.0:8080

The parser now handles both formats by using the queried port
as the container_port when parsing the simple format.

Also restores the host_port() test in testing_utilities example
now that the underlying bug is fixed.

Fixes #231
@joshrotenberg joshrotenberg merged commit 9320166 into main Jan 6, 2026
11 checks passed
@joshrotenberg joshrotenberg deleted the fix/port-command-parser branch January 6, 2026 01:29
@github-actions github-actions Bot mentioned this pull request Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: PortCommand parser doesn't handle single-port query format

1 participant