Skip to content

Commit

Permalink
Transforming wildcard syntax to regex, which is used by WebProxy for …
Browse files Browse the repository at this point in the history
…NoProxy bypassing
  • Loading branch information
Reibel, Christian (GfK) authored and Reibel, Christian (GfK) committed Oct 4, 2016
1 parent 434251c commit 1744015
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Paket.Core/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,9 @@ let envProxies () =
// under mono, env vars are case sensitive
if isNull v then Environment.GetEnvironmentVariable(name.ToLowerInvariant()) else v
let bypassList =
let noproxy = getEnvValue "NO_PROXY"
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)
let getCredentials (uri:Uri) =
Expand Down
17 changes: 16 additions & 1 deletion tests/Paket.Tests/UtilsSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,25 @@ let ``get http env proxy with bypass list``() =
p.Address |> shouldEqual (new Uri("http://proxy.local:8080"))
p.BypassProxyOnLocal |> shouldEqual true
p.BypassList.Length |> shouldEqual 2
p.BypassList.[0] |> shouldEqual ".local"
p.BypassList.[0] |> shouldEqual "\\.local"
p.BypassList.[1] |> shouldEqual "localhost"
p.Credentials |> shouldEqual null

[<Test>]
let ``get http env proxy with bypass list containing wildcards``() =
use v = new DisposableEnvVar("http_proxy", "http://proxy.local:8080")
use w = new DisposableEnvVar("no_proxy", ".local,localhost,*.asdf.com")
let pOpt = envProxies().TryFind "http"
Option.isSome pOpt |> shouldEqual true
let p = Option.get pOpt
p.Address |> shouldEqual (new Uri("http://proxy.local:8080"))
p.BypassProxyOnLocal |> shouldEqual true
p.BypassList.Length |> shouldEqual 3
p.BypassList.[0] |> shouldEqual "\\.local"
p.BypassList.[1] |> shouldEqual "localhost"
p.BypassList.[2] |> shouldEqual "\\.*\\.asdf\\.com"
p.Credentials |> shouldEqual null

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

0 comments on commit 1744015

Please sign in to comment.