diff --git a/net-doc/net/scribblings/url.scrbl b/net-doc/net/scribblings/url.scrbl index 0fc4adceca..d6e402b455 100644 --- a/net-doc/net/scribblings/url.scrbl +++ b/net-doc/net/scribblings/url.scrbl @@ -171,7 +171,8 @@ scheme @racket["http"].} Generates a string corresponding to the contents of a @racket[url] struct. For a @racket["file:"] URL, the URL must not be relative, and -the result always starts @litchar{file://}. +the result always starts @litchar{file://}. For a URL with a host, +user, or port, its path must be either absolute or empty. The @racket[url->string] procedure uses @racket[alist->form-urlencoded] when formatting the query, so it is diff --git a/net-test/tests/net/url-string.rkt b/net-test/tests/net/url-string.rkt index a7b23d54e3..94ff1a4d68 100644 --- a/net-test/tests/net/url-string.rkt +++ b/net-test/tests/net/url-string.rkt @@ -91,6 +91,11 @@ (test-s->u #("http" #f "www.drscheme.org" #f #t (#("a" "x") #("b") #("c" "b")) () #f) "http://www.drscheme.org/a;x/b/c;b") + ;; Allow empty port spec + (test #("http" #f "www.drscheme.org" #f #t (#("a")) () #f) + url->vec + (string->url "http://www.drscheme.org:/a")) + ;; Test IPv6 literal addresses, which are written with "[...]" around ;; an address that contains ":"s: (test-s->u #("http" #f "::1" #f #t (#("a") #("b") #("c")) () "joe") @@ -158,6 +163,18 @@ (string->url "a*b://www.foo.com/") =error> url-exception? (string->url "a b://www.foo.com/") =error> url-exception?) + ;; test relatve path after host + (test + (string->url "http://www.foo.com:oops/") =error> url-exception? + (string->url "http://www.foo.com:0oops/") =error> url-exception? + + ;; Empty "relative" path is ok with host: + (url->string (url "http" #f "www.drscheme.org" #f #f (list) (list) #f)) + => "http://www.drscheme.org" + ;; Non-empty "relative" path is not ok with host: + (url->string (url "http" #f "www.drscheme.org" #f #f (list (path/param "a" (list))) (list) #f)) + =error> exn:fail:contract?) + ;; test file: urls (test-s->u #("file" #f "" #f #t (#("abc") #("def.html")) () #f) "file:///abc/def.html")