Repository navigation
Accept bracketed IPv6 hosts in --uri - #720
Merged
Merged
Conversation
parse_uri() split host and port at the first ':' after the credentials, so redis://[::1]:6379 (the RFC 3986 form redis-cli -u accepts) failed with "invalid port number ':1]:6379'". Brackets were not handled at all, so the host would have kept its '[' ']' even with a correct port split. When the host starts with '[', take everything up to the matching ']' as the host (without brackets) and require ']' to be followed by ':PORT' or nothing (the '/db' part is already cut off). An unterminated '[', empty brackets, or trailing garbage after ']' is rejected with "invalid IPv6 host". The port still goes through parse_port(), and non-bracketed URIs are parsed exactly as before. Fixes #701 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The live IPv6 test let mb.py add --server 127.0.0.1 --port <port>, so it still passed if the URI dropped the bracketed host or ignored its port. Pass explicit decoy --server/--port values that the URI has to override. Assert that a rejected bracketed URI does not echo its password, and that bracketed hosts without a port ([::1], [::1]/0, [::1]/) parse cleanly. Mirror the new --help line in memtier_benchmark.1. Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira
force-pushed
the
fix-701-ipv6-uri
branch
from
October 16, 2026 14:00
6410a91 to
8292e98
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Behaviour decision:
--urinow accepts a bracketed IPv6 host,redis://[::1]:6379, the same RFC 3986 form thatredis-cli -uaccepts. The brackets are removed from the host. Malformed bracket forms are rejected during argument parsing. URIs without brackets are parsed exactly as before.Problem
memtier_benchmark --uri="redis://[::1]:6379"fails witherror: invalid port number ':1]:6379'.and exit code 1.redis://[::1]:6379/0andredis://[::1]fail the same way.-s ::1 -p 6379works, so only the URI path is affected (#701).Root cause
parse_uri()split host and port withstrchr(host_start, ':'), which finds the first:inside[::1]. Brackets were not handled anywhere, so even with a correct port split the host would have kept its[and].Fix
In
parse_uri(), if the host starts with[:], without the brackets;]must be followed by:PORTor by nothing (the/dbpart is cut off earlier);[, empty[], or anything else after]([::1]x) is rejected witherror: invalid IPv6 host '...' in URI.The message prints only the host part, so credentials from the URI are not echoed.The port still goes through
parse_port()from #699. The--helptext for--urinow mentions the bracket form. The diff is limited toparse_uri(), one help line and the tests.Tests
tests_oss_simple_flow.py::test_uri_ipv6_bracketed_hostruns a short benchmark with--uri=redis://[::1]:PORT. It also passes decoy values,--server=host-must-be-overridden.invalid --port=1, withexplicit_connect_args, so the run only succeeds if the URI really sets both the host and the port. It skips on unix-socket envs, on non-local hosts, and when[::1]:PORTis not reachable.test_cli_validation_ports.py::test_uri_rejects_malformed_ipv6_hostchecks that[::1,[::1]x,[::1]x:6379,[]:6379,[::1]:,[::1]:65537andu:s3cret@[::1are rejected with the right diagnostic, and that the password is never echoed to stderr.test_cli_validation_ports.py::test_uri_accepts_ipv6_host_without_portchecks that[::1],[::1]/0and[::1]/parse with no diagnostic and reach the connect stage against a refused port.Measured locally on Redis 8.6.0. The RLTest-started server listens on
::1, so the connect test really ran and was not skipped:All of
test_cli_validation_ports.pypasses 5/5 with this PR.Manual matrix against
redis-server --bind ::1 127.0.0.1:redis://[::1]:Pinvalid port number ':1]:P', rc=1redis://[::1]:P/0invalid port number, rc=1redis://[::1]invalid port number ':1]', rc=1[::1]:6379(default port)redis://[::1invalid port number ':1'invalid IPv6 host '[::1'redis://[::1]xinvalid port number ':1]x'invalid IPv6 host '[::1]x'redis://[]:Pinvalid IPv6 host '[]:P'redis://[::1]:99999invalid port number ':1]:99999'invalid port number '99999'redis://127.0.0.1:PFixes #701
Affected versions
2.2.0 through 2.5.2 (latest) and master.
parse_uri()with the first-:split. The first tag that contains it is 2.2.0.🤖 Generated with Claude Code
Note
Low Risk
Scoped to URI argument parsing and validation; connection behavior for existing IPv4 URIs is unchanged.
Overview
Fixes
--uriso bracketed IPv6 hosts work likeredis-cli -u(e.g.redis://[::1]:6379), instead of treating the first:inside::1as the port separator.parse_uri()now strips[/], finds the port only after], and rejects malformed bracket syntax at parse time witherror: invalid IPv6 host. IPv4 and unbracketed URIs behave as before. Help text documents the bracket form.Tests cover a live benchmark on
[::1](with skips when unreachable) and CLI validation for bad IPv6 URI shapes and port errors.Reviewed by Cursor Bugbot for commit 6410a91. Bugbot is set up for automated code reviews on this repo. Configure here.