Mirror: A Node.js fetch shim using built-in Request, Response, and Headers (but without native fetch)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: Fix pattern handling for `NO_PROXY` (#18)

authored by

Phil Pluckthun and committed by
GitHub
02c74c23 18219203

+20 -11
+5
.changeset/chilly-hands-decide.md
··· 1 + --- 2 + 'fetch-nodeshim': patch 3 + --- 4 + 5 + Fix typo in `NO_PROXY` construction
+15 -11
src/agent.ts
··· 22 22 process.env.HTTPS_PROXY ?? process.env.https_proxy; 23 23 const getNoProxy = () => process.env.NO_PROXY ?? process.env.no_proxy; 24 24 25 - const createProxyPattern = (pattern: string): RegExp => { 26 - pattern = pattern.trim().replace(/\./g, '\\.').replace(/\*/g, '[\w.]+'); 25 + const createProxyPattern = (pattern: string): RegExp | null => { 26 + pattern = pattern.trim(); 27 27 if (!pattern.startsWith('.')) pattern = `^${pattern}`; 28 28 if (!pattern.endsWith('.') || pattern.includes(':')) pattern += '$'; 29 - return new RegExp(pattern, 'i'); 29 + pattern = pattern.replace(/\./g, '\\.').replace(/\*/g, '[\\w.]+'); 30 + return pattern ? new RegExp(pattern, 'i') : null; 30 31 }; 31 32 32 33 const matchesNoProxy = (options: { ··· 41 42 } else if (NO_PROXY) { 42 43 for (const noProxyPattern of NO_PROXY.split(',')) { 43 44 const hostPattern = createProxyPattern(noProxyPattern); 44 - const hostname = options.hostname || options.host; 45 - const origin = 46 - hostname && `${hostname}:${options.port || options.defaultPort || 80}`; 47 - if ( 48 - (hostname && hostPattern.test(hostname)) || 49 - (origin && hostPattern.test(origin)) 50 - ) { 51 - return true; 45 + if (hostPattern) { 46 + const hostname = options.hostname || options.host; 47 + const origin = 48 + hostname && 49 + `${hostname}:${options.port || options.defaultPort || 80}`; 50 + if ( 51 + (hostname && hostPattern.test(hostname)) || 52 + (origin && hostPattern.test(origin)) 53 + ) { 54 + return true; 55 + } 52 56 } 53 57 } 54 58 return false;