Skip to content

Commit b114d33

Browse files
authored
feat: add support for SOCKS to PROXY_URL_REGEX (#498)
This PR adds support for SOCKS protocols into the `PROXY_URL_REGEX`. I also added unit tests for it while I was at it.
1 parent 1713430 commit b114d33

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

packages/consts/src/regexs.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@ export const APIFY_PROXY_VALUE_REGEX = /^[\w._~]+$/;
5353
/**
5454
* Regular expression to validate proxy urls, matches
5555
* http://asd:[email protected]:8000
56-
* http://asd:[email protected]:8000/
5756
* http://123123:qweqwe:[email protected]:55555
5857
* http://proxy.apify.com:5000
5958
* http://[email protected]:5000
6059
*/
61-
export const PROXY_URL_REGEX = /^https?:\/\/(([^:]+:)?[^@]*@)?[^.:@]+\.[^:]+:[\d]+?$/;
60+
export const PROXY_URL_REGEX = /^(socks(4|4a|5|5h)?|https?):\/\/(([^:]+:)?[^@]*@)?[^.:@]+\.[^:]+:[\d]+?$/;
6261

6362
/**
6463
* AWS S3 docs say:

packages/input_schema/src/intl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const intlStrings = {
2020
'inputSchema.validation.proxyGroupsNotAvailable':
2121
'You currently do not have access to proxy groups: {groups}',
2222
'inputSchema.validation.customProxyInvalid':
23-
'Proxy URL "{invalidUrl}" has invalid format, it must be http[s]://[username[:password]]@hostname:port.',
23+
'Proxy URL "{invalidUrl}" has invalid format, it must be socks[4|4a|5|5h]|http[s]://[username[:password]]@hostname:port.',
2424
'inputSchema.validation.apifyProxyCountryInvalid':
2525
'Country code "{invalidCountry}" is invalid. Only ISO 3166-1 alpha-2 country codes are supported.',
2626
'inputSchema.validation.apifyProxyCountryWithoutApifyProxyForbidden':

test/regexs.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,30 @@ const tests = {
317317
'https://www.linkedin.com/company/companyname/extra/extra/',
318318
],
319319
},
320+
PROXY_URL_REGEX: {
321+
valid: [
322+
'http://asd:[email protected]:8000',
323+
'http://asd:[email protected]:8000',
324+
'http://123123:qweqwe:[email protected]:55555',
325+
'http://proxy.apify.com:5000',
326+
'http://[email protected]:5000',
327+
'https://proxy.apify.com:5000',
328+
'socks://proxy.apify.com:5000',
329+
'socks4://proxy.apify.com:5000',
330+
'socks4a://proxy.apify.com:5000',
331+
'socks5://proxy.apify.com:5000',
332+
'socks5h://proxy.apify.com:5000',
333+
],
334+
invalid: [
335+
'http://@proxy.apify.com:8000/',
336+
'https://proxy.apify.com',
337+
'httpss://proxy.apify.com:5000',
338+
'htt://proxy.apify.com:5000',
339+
'soks://proxy.apify.com:5000',
340+
'socks3://proxy.apify.com:5000',
341+
'socks6://proxy.apify.com:5000',
342+
],
343+
},
320344
};
321345

322346
describe('regexps', () => {

0 commit comments

Comments
 (0)