{"record":{"id":"5b69f275f555f9f4","repo":"redis/redis-py","slug":"field-name-must-not-contain-spaces-newlines-no","errorCode":null,"errorMessage":"{field_name} must not contain spaces, newlines, non-printable characters, or braces","messagePattern":"(.+?) must not contain spaces, newlines, non-printable characters, or braces","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"redis/driver_info.py","lineNumber":21,"sourceCode":"from dataclasses import dataclass, field\nfrom typing import List, Optional\n\nfrom redis.utils import SENTINEL\n\n_BRACES = {\"(\", \")\", \"[\", \"]\", \"{\", \"}\"}\n\n\ndef _validate_no_invalid_chars(value: str, field_name: str) -> None:\n    \"\"\"Ensure value contains only printable ASCII without spaces or braces.\n\n    This mirrors the constraints enforced by other Redis clients for values that\n    will appear in CLIENT LIST / CLIENT INFO output.\n    \"\"\"\n\n    for ch in value:\n        # printable ASCII without space: '!' (0x21) to '~' (0x7E)\n        if ord(ch) < 0x21 or ord(ch) > 0x7E or ch in _BRACES:\n            raise ValueError(\n                f\"{field_name} must not contain spaces, newlines, non-printable characters, or braces\"\n            )\n\n\ndef _validate_driver_name(name: str) -> None:\n    \"\"\"Validate an upstream driver name.\n\n    The name should look like a typical Python distribution or package name,\n    following a simplified form of PEP 503 normalisation rules:\n\n    * start with a lowercase ASCII letter\n    * contain only lowercase letters, digits, hyphens and underscores\n\n    Examples of valid names: ``\"django-redis\"``, ``\"celery\"``, ``\"rq\"``.\n    \"\"\"\n\n    import re\n","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/driver_info.py#L3-L39","documentation":"_validate_no_invalid_chars (redis/driver_info.py:21) rejects any character outside printable ASCII 0x21-0x7E and also forbids the brace set ()[]{}. These strings become the LIB-NAME / LIB-VER sent via CLIENT SETINFO and appear in CLIENT LIST / CLIENT INFO output, where spaces, newlines and braces would corrupt Redis' single-line format or enable injection. The validator runs on the base lib name, the lib version, each upstream driver name, and each upstream driver version.","triggerScenarios":"Calling DriverInfo(name=..., lib_version=...) or driver_info.add_upstream_driver(name, version) with a value containing a space, tab, newline, non-ASCII char (e.g. a unicode dash), or any of ()[]{}. Passing a version with a trailing newline or a driver name copied from a rich-text doc with smart quotes will trigger it.","commonSituations":"Auto-derived versions that include git describe suffixes with special chars; pasting driver names from marketing copy; unicode lookalikes (en-dash instead of hyphen); building lib_name from user input that contains spaces.","solutions":["Sanitize the value to printable ASCII without spaces or braces before constructing DriverInfo or calling add_upstream_driver.","Strip whitespace/newlines and replace unicode dashes/quotes with their ASCII equivalents.","Keep driver/version strings to the form /^[!-~]+$/ minus ()[]{} — typically alnum, dots, hyphens, underscores."],"exampleFix":"// before\ninfo = redis.driver_info.DriverInfo(name='My Redis Client 2.0')\n// after\ninfo = redis.driver_info.DriverInfo(name='MyRedisClient-2.0')","handlingStrategy":"validation","validationCode":"import re\ndef safe_driver_value(v: str) -> str:\n    return re.sub(r'\\s+', '', v).encode('ascii', 'ignore').decode('ascii')\ndef is_valid_value(v: str) -> bool:\n    return all(0x21 <= ord(c) <= 0x7E and c not in '()[]{}' for c in v)","typeGuard":"def is_clean_ascii(v) -> bool:\n    return isinstance(v, str) and all(0x21 <= ord(c) <= 0x7E and c not in '()[]{}' for c in v)","tryCatchPattern":null,"preventionTips":["Keep driver/version strings to alnum, dots, hyphens, underscores only.","Normalize unicode dashes/quotes/smart punctuation to ASCII before constructing DriverInfo.","Strip whitespace and newlines from auto-derived version strings."],"tags":["driver-info","validation","client-setinfo","ascii"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}