Skip to content

Commit 8e5abe5

Browse files
committed
http: allow NO_PROXY split with space
1 parent 1ceb375 commit 8e5abe5

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

docs/netconfig.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ In some circumstances you may wish to bypass a configured proxy for specific
6161
addresses. GCM Core supports the cURL environment variable `NO_PROXY` for this
6262
scenariom, as does Git itself.
6363

64-
The `NO_PROXY` environment variable should contain a comma (`,`) separated list
65-
of regular expressions to match hosts that should not be proxied (should connect
66-
directly).
64+
The `NO_PROXY` environment variable should contain a comma (`,`) or space (` `)
65+
separated list of regular expressions to match hosts that should not be proxied
66+
(should connect directly).
6767

6868
**Example:**
6969

src/shared/Microsoft.Git.CredentialManager.Tests/SettingsTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,42 @@ public void Settings_ProxyConfiguration_GitHttpConfig_ReturnsValue()
556556
Assert.False(actualConfig.IsDeprecatedSource);
557557
}
558558

559+
[Fact]
560+
public void Settings_ProxyConfiguration_NoProxyMixedSplitChar_ReturnsValue()
561+
{
562+
const string remoteUrl = "http://example.com/foo.git";
563+
const string section = Constants.GitConfiguration.Http.SectionName;
564+
const string property = Constants.GitConfiguration.Http.Proxy;
565+
var remoteUri = new Uri(remoteUrl);
566+
567+
const string expectedUserName = "john.doe";
568+
const string expectedPassword = "letmein123";
569+
var expectedAddress = new Uri("http://proxy.example.com");
570+
var settingValue = new Uri("http://john.doe:[email protected]");
571+
var bypassList = new List<string> {"contoso.com", "fabrikam.com", "example.com"};
572+
573+
var envars = new TestEnvironment
574+
{
575+
Variables = {[Constants.EnvironmentVariables.CurlNoProxy] = "contoso.com, fabrikam.com example.com,"}
576+
};
577+
var git = new TestGit();
578+
git.GlobalConfiguration[$"{section}.{property}"] = settingValue.ToString();
579+
580+
var settings = new Settings(envars, git)
581+
{
582+
RemoteUri = remoteUri
583+
};
584+
585+
ProxyConfiguration actualConfig = settings.GetProxyConfiguration();
586+
587+
Assert.NotNull(actualConfig);
588+
Assert.Equal(expectedAddress, actualConfig.Address);
589+
Assert.Equal(expectedUserName, actualConfig.UserName);
590+
Assert.Equal(expectedPassword, actualConfig.Password);
591+
Assert.Equal(bypassList, actualConfig.BypassHosts);
592+
Assert.False(actualConfig.IsDeprecatedSource);
593+
}
594+
559595
[Fact]
560596
public void Settings_ProxyConfiguration_CurlHttpEnvar_ReturnsValue()
561597
{

src/shared/Microsoft.Git.CredentialManager/Settings.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ bool TryGetUriSetting(string envarName, string section, string property, out Uri
397397
return false;
398398
}
399399

400+
char[] bypassListSeparators = {',', ' '};
401+
400402
ProxyConfiguration CreateConfiguration(Uri uri, bool isLegacy = false)
401403
{
402404
// Strip the userinfo, query, and fragment parts of the Uri retaining only the scheme, host, port, and path
@@ -413,9 +415,9 @@ ProxyConfiguration CreateConfiguration(Uri uri, bool isLegacy = false)
413415

414416
// Get the proxy bypass host names
415417
var bypassHosts = new List<string>();
416-
if (_environment.Variables.TryGetValue(KnownEnvars.CurlNoProxy, out string noProxyStr))
418+
if (_environment.Variables.TryGetValue(KnownEnvars.CurlNoProxy, out string noProxyStr) && noProxyStr != null)
417419
{
418-
bypassHosts = noProxyStr.Split(',').ToList();
420+
bypassHosts.AddRange(noProxyStr.Split(bypassListSeparators, StringSplitOptions.RemoveEmptyEntries));
419421
}
420422

421423
return new ProxyConfiguration(address, userName, password, bypassHosts, isLegacy);

0 commit comments

Comments
 (0)