Skip to content

Commit

Permalink
fix: decode special characters in proxy username and password (#2696
Browse files Browse the repository at this point in the history
)

When using `newProxyInfo` function, the `username` and `password`
extracted from `proxyUrl` are now properly decoded.

https://apify.slack.com/archives/C0L33UM7Z/p1727966399183259
  • Loading branch information
B4nan authored Oct 4, 2024
1 parent 6fa170f commit 0f0fcc5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/proxy_configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ export class ProxyConfiguration {
return {
sessionId,
url,
username,
password,
username: decodeURIComponent(username),
password: decodeURIComponent(password),
hostname,
port: port!,
proxyTier: tier,
Expand Down
15 changes: 15 additions & 0 deletions test/core/proxy_configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ describe('ProxyConfiguration', () => {
expect(await proxyConfiguration.newProxyInfo(sessionId)).toEqual(proxyInfo);
});

test('newProxyInfo() works with special characters', async () => {
const url = 'http://user%40name:pass%40word@proxy.com:1111';
const proxyConfiguration = new ProxyConfiguration({ proxyUrls: [url] });

const proxyInfo = {
sessionId: `${sessionId}`,
url,
hostname: 'proxy.com',
username: 'user@name',
password: 'pass@word',
port: '1111',
};
expect(await proxyConfiguration.newProxyInfo(sessionId)).toEqual(proxyInfo);
});

test('should throw on invalid newUrlFunction', async () => {
const newUrlFunction = () => {
return 'http://proxy.com:1111*invalid_url';
Expand Down

0 comments on commit 0f0fcc5

Please sign in to comment.