Skip to content

Split CLIENT LIST records on newline only - #4556

Merged
petyaslavova merged 3 commits into
redis:masterfrom
arxhr007:fix/client-list-record-separators
Nov 3, 2026
Merged

petyaslavova merged 3 commits into
redis:masterfrom
arxhr007:fix/client-list-record-separators

Conversation

@arxhr007

@arxhr007 arxhr007 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Description of change

parse_client_list splits the CLIENT LIST reply with str.splitlines(). That also breaks on the control characters VT, FF, FS, GS, RS, NEL (U+0085), U+2028 and U+2029, not only on newline. The server does not forbid them inside a field: it only rejects spaces and null characters in ACL usernames, and a Unix-socket addr can contain any path character. A record is then cut in two, and the second half comes back as an extra, mostly empty dict.

_client_list_iter (the as_iter=True path) already splits on newline only, so the two paths disagree on the same reply:

>>> reply = "id=1 addr=127.0.0.1:1 user=a<U+2028>b flags=N\nid=2 addr=127.0.0.1:2"   # <U+2028> is the real character
>>> parse_client_list(reply)
[{'id': '1', 'addr': '127.0.0.1:1', 'user': 'a'}, {'flags': 'N'}, {'id': '2', 'addr': '127.0.0.1:2'}]
>>> list(parse_client_list(reply, as_iter=True))
[{'id': '1', 'addr': '127.0.0.1:1', 'user': 'a<U+2028>b', 'flags': 'N'}, {'id': '2', 'addr': '127.0.0.1:2'}]

The eager path now builds its list from _client_list_iter, so both split the same way and the list of lines is no longer built. It is shared by the sync and async clients, so nothing else needs mirroring. No signature or return type changes.

parse_info and parse_cluster_nodes also use splitlines(); I left them alone to keep this to one function.

Pull Request check-list

  • Do tests and lints pass with this change? ruff check and ruff format --check pass on both changed files. pytest tests/test_parsers passes locally (60 passed). The tests that need a Redis server were not run here; CI covers those.
  • Do the CI tests pass with this change? Yes: all checks pass on the latest commit (130 passed, 2 skipped by design), including the Redis 7.2 to 8.12 matrix on Python 3.11 to 3.15 and PyPy, the plain, hiredis and uvloop setups, linters and docs.
  • Is the new or changed code fully tested? New parametrized test test_parse_client_list_only_splits_records_on_newline covers VT, FF, CR, FS, GS, RS, NEL, U+2028 and U+2029 for both the eager and the as_iter path. Without the change to helpers.py the 8 cases other than CR fail (the reply comes back as 3 records instead of 2); with it they pass.
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)? Not needed, no API change.
  • Is there an example added to the examples folder (if applicable)? Not applicable.

parse_client_list split the reply with str.splitlines(), which also breaks on \x0b, \x0c, \x1c-\x1e, \x85, \u2028 and \u2029. Those characters are allowed in ACL usernames and unix socket paths, so a single record was cut in two. The as_iter path already split on newline only; the eager path now uses the same generator.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T16:18:07.447771Z f9aa6c8 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@petyaslavova petyaslavova left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @arxhr007, thank you for your contribution!

The fix looks right to me: CLIENT LIST separates records with "\n" only, and reusing _client_list_iter for the eager path makes both paths agree while removing the duplicated split logic. This is good to merge once CI is green.

One optional addition: str.splitlines() also breaks on \r (0x0D), so it would be worth adding it to the parametrized separators in the new test.

@petyaslavova petyaslavova added the maintenance Maintenance (CI, Releases, etc) label Nov 2, 2026
@arxhr007

arxhr007 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I added \r (0x0D) to the separators in the parametrized test; all 9 cases pass locally.

@petyaslavova
petyaslavova merged commit 58bc34e into redis:master Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Maintenance (CI, Releases, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants