Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transforming wildcard syntax to regex, which is used by WebProxy for … #1939

Merged
merged 1 commit into from
Oct 5, 2016
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
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