forwardemail / forwardemail/superagent

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

Open
#1,767 0 comments 0 reactions 0 assignees View on GitHub
Bug
Dominant language
JavaScript
Stars
16.6k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

## 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](https://github.com/ladjs/superagent/blob/e7970e94504ea1358ecb0ea6f739e645644eb35a/src/node/index.js#L728) 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

```javascript
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.
```javascript
await superagent.get('http://the/actual/url').socket('/path/to/socket.sock')

```
## Checklist

- [x] I have searched through GitHub issues for similar issues.
- [x] I have completely read through the README and documentation.
- [x] I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.