ladjs / superagent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
https://ladjs.github.io/superagent/
MIT License
16.57k stars 1.33k forks source link

Unix socket is expected to be encoded with `%2F` #1767

Open ghost opened 1 year ago

ghost commented 1 year ago

Describe the bug

Node.js version: 18.15.0

OS version: Ubuntu 20.4

Superagent version: 8.0.9

Description: As we can see from line 728 of src/node/index.js superagent expects a unix socket address like /path/to/socket.sock to be formatted as %2Fpath%2Fto%2Fsocket.sock, to then separate the socket path from the actual url with a regular expression.

If the unix path is not formatted as required, an unclear error will be thrown: Cannot read properties of null (reading '1') which is caused by the regexr not being able to match the unix socket path.

Code to reproduce

await superagent .get('http+unix:///path/to/socket.sock/the/actual/url');

// will throw: Cannot read properties of null (reading '1')

It would be much easier to just skip this whole pattern matching and provide and option to directly pass the socket path.

await superagent.get('http://the/actual/url').socket('/path/to/socket.sock')

Checklist