fix(client): parse unix socket urls#3280
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit bbdc01b. Configure here.
| } | ||
|
|
||
| parsed.database = parsedDatabase; | ||
| } |
There was a problem hiding this comment.
Empty db query parameter silently maps to database 0
Low Severity
When the db query parameter is present but empty (e.g., unix:///tmp/redis.sock?db= or unix:///tmp/redis.sock?db), searchParams.get('db') returns '', which passes the !== null check. Number('') evaluates to 0 and isNaN(0) is false, so parsed.database is silently set to 0. Given the PR explicitly validates malformed database values (e.g., ?db=NaN), an empty value likely qualifies as malformed and probably warrants a similar TypeError rather than a silent default.
Reviewed by Cursor Bugbot for commit bbdc01b. Configure here.
|
Hi @raashish1601, thanks for the PR, i will look into it, hopefully soon! |


Summary
Adds
unix://URL parsing toRedisClient.parseURL, mapping the socket path intosocket.pathso callers can configure Unix domain socket connections through the sameurloption as TCP/TLS connections.Supported forms include:
unix:///tmp/redis.sock?db=2unix://user:secret@/tmp/redis.sock?db=3The parser also preserves the existing async credentials provider behavior for URL credentials and validates malformed Unix socket authority/database values.
This PR also includes small typed cleanups in
client/index.tsbecausenpm run lint:changedlints the whole touched file and current master has pre-existing lint violations in that file.Closes #2530.
Validation
node -r ts-node/register/transpile-onlychecks for Unix socket path, db, credentials provider, and invalid authoritynpm run lint:changednpm run buildgit diff --checkI also attempted
npx mocha --require ts-node/register/transpile-only packages/client/lib/client/index.spec.ts --grep unix://, but this repo starts its Docker-backed Redis test environment in global hooks before grep-selected tests run. It failed locally atspawn docker ENOENTbecause Docker is not installed in this environment.Note
Medium Risk
Moderate risk because it changes URL parsing and client option derivation, which can affect connection/auth configuration across callers; coverage is improved with new unit tests for unix URLs and invalid inputs.
Overview
Adds
unix://URL support toRedisClient.parseURL, allowing Unix domain socket connections viaurlby mapping the decoded socket path intosocket.pathand parsingdbfrom the query string.Refactors credential extraction into a shared helper so both TCP/TLS and Unix URLs produce
username/passwordplus the asynccredentialsProvider, and adds validation for malformed Unix authority/path/database values.Includes small TypeScript typing/lint cleanups around the client factory/proxy types,
Multiconstruction, and invalidate push handler typing.Reviewed by Cursor Bugbot for commit bbdc01b. Bugbot is set up for automated code reviews on this repo. Configure here.