Percent encoded hosts do not seem to be working anymore.
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
Hi.
I am trying to connect to a local unix socket in a nonstandard location, using a connection string that looks like this:
postgres://felix@%2Frun%2Fuser%2F1000%2Fdevenv-85050cd%2Fpostgres/mercury
Now, as far as I understand it, the library should percent-decode the host part and then connect to the unix socket.
However, it seems to not do this decoding. Additionally, when spelunking through the source, it seems to be broken for quite a while.
Of course, it could be that I am missing something here, but if I add calls to decodeURIComponent to the host and hostname components, same as for the username and password it works as expected.
For reference, the current code and my thoughts on the issue:
function parseUrl(url) {
if (!url || typeof url !== 'string')
return { url: { searchParams: new Map() } }
let host = url
host = host.slice(host.indexOf('://') + 3).split(/[?/]/)[0]
host = decodeURIComponent(host.slice(host.indexOf('@') + 1))
// the decoded host here is not a substring of the url string
const urlObj = new URL(url.replace(host, host.split(',')[0])) // if the host was url decoded,it is never replaced, as the decoded host is not a substring
return {
url: {
username: decodeURIComponent(urlObj.username),
password: decodeURIComponent(urlObj.password),
host: urlObj.host, // we are using the unmodified host from the url, not the decoded value
hostname: urlObj.hostname, // we are using the unmodified host from the url, not the decoded value
port: urlObj.port,
pathname: urlObj.pathname,
searchParams: urlObj.searchParams
},
multihost: host.indexOf(',') > -1 && host
}
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the parseUrl entry point shown in the issue and trace how the URL host and hostname are passed into the connection setup. Verify that percent-encoded Unix-socket hosts are decoded without breaking multihost URLs, and confirm that the example connection string reaches the intended socket.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100