diff --git a/pkgs/net-test/tests/net/bad-proxy-envvar.rkt b/pkgs/net-test/tests/net/bad-proxy-envvar.rkt new file mode 100644 index 0000000000..ee8a83fc99 --- /dev/null +++ b/pkgs/net-test/tests/net/bad-proxy-envvar.rkt @@ -0,0 +1,11 @@ +#lang racket/base +(parameterize ([current-environment-variables + (environment-variables-copy + (current-environment-variables))] + [current-namespace (make-base-namespace)] + [current-logger (make-logger)]) + ;; There are not a lot of strings that `url->string` rejects, but + ;; this one of them: + (putenv "http_proxy" "http://example.com:8080 ") + ;; Dynamic load so that we get to change the logger first + ((dynamic-require 'net/url 'current-proxy-servers))) diff --git a/racket/collects/net/url.rkt b/racket/collects/net/url.rkt index 1f5e3aaca9..d5928cf47d 100644 --- a/racket/collects/net/url.rkt +++ b/racket/collects/net/url.rkt @@ -29,6 +29,12 @@ "https" "git")) +;; Like `string->url`, but returns #f for an error, intended for use +;; with pattern matching. +(define (string->url* str) + (with-handlers ([url-exception? (lambda (exn) #f)]) + (string->url str))) + ;; env->c-p-s-entries: (listof (listof string)) -> (listof (list string string num)) ;; ;; "http" protocol is proxied by http proxy @@ -41,11 +47,11 @@ (match (getenv envvar) [#f #f] ["" null] - [(app string->url + [(app string->url* (url (and proxying-scheme "http") #f (? string? host) (? integer? port) _ (list) (list) #f)) (list (list proxied-scheme host port))] - [(app string->url + [(app string->url* (url (and proxying-scheme "http") _ (? string? host) (? integer? port) _ _ _ _)) (log-net/url-warning "~s contains somewhat invalid proxy URL format" envvar)