Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/Paket.Core/Common/NetUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,18 @@ let envProxies () =
if isNull v then Environment.GetEnvironmentVariable(name.ToLowerInvariant()) else v
let bypassList =
let noproxyString = getEnvValue "NO_PROXY"
let noproxy = if not (String.IsNullOrEmpty noproxyString) then System.Text.RegularExpressions.Regex.Escape(noproxyString).Replace(@"*", ".*") else noproxyString

if String.IsNullOrEmpty noproxy then [||] else
noproxy.Split([| ',' |], StringSplitOptions.RemoveEmptyEntries)
if String.IsNullOrEmpty noproxyString then [||] else
// Each comma-separated entry may contain '*' as a wildcard. We escape the entry as a
// regex, but must treat '*' specially: escaping the whole string first (as was done
// previously) turns '*' into the literal '\*', so a later ".Replace(\"*\", \".*\")" has
// no effect and wildcard bypass entries (e.g. "*.internal.company.com") never match.
// Instead, split on '*', escape each literal segment, and re-join with ".*".
let escapeWithWildcard (entry:string) =
entry.Split('*')
|> Array.map System.Text.RegularExpressions.Regex.Escape
|> String.concat ".*"
noproxyString.Split([| ',' |], StringSplitOptions.RemoveEmptyEntries)
|> Array.map escapeWithWildcard
let getCredentials (uri:Uri) =
let userPass = uri.UserInfo.Split([| ':' |], 2)
if userPass.Length <> 2 || userPass.[0].Length = 0 then None else
Expand Down
18 changes: 17 additions & 1 deletion tests/Paket.Tests/UtilsSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,26 @@ let ``get http env proxy with bypass list containing wildcards``() =
p.BypassList.Length |> shouldEqual 3
p.BypassList.[0] |> shouldEqual "\\.local"
p.BypassList.[1] |> shouldEqual "localhost"
p.BypassList.[2] |> shouldEqual "\\.*\\.asdf\\.com"
p.BypassList.[2] |> shouldEqual ".*\\.asdf\\.com"
#endif
p.Credentials |> shouldEqual null

[<Test>]
let ``no_proxy wildcard bypass entry actually bypasses matching subdomain``() =
use v = new DisposableEnvVar("http_proxy", "http://proxy.local:8080")
use w = new DisposableEnvVar("no_proxy", "*.internal.company.com")
let pOpt = envProxies().TryFind "http"
Option.isSome pOpt |> shouldEqual true
let p = Option.get pOpt
#if WEBPROXY_NETSTANDARD
ignore p //TODO readd check
#else
// were escaped incorrectly and therefore never matched any host, even though they should
// bypass the proxy for matching subdomains.
p.IsBypassed(new Uri("http://nuget.internal.company.com")) |> shouldEqual true
p.IsBypassed(new Uri("http://example.com")) |> shouldEqual false
#endif

[<Test>]
let ``should simplify path``() =
let p0 = "/Users/dna/Downloads/test/aa/src/bb"
Expand Down
Loading