diff --git a/collects/net/url-structs.rkt b/collects/net/url-structs.rkt index 6aece917c5..094d848b21 100644 --- a/collects/net/url-structs.rkt +++ b/collects/net/url-structs.rkt @@ -13,7 +13,7 @@ [port (or/c false/c number?)] [path-absolute? boolean?] [path (listof path/param?)] - [query (or/c false/c (listof (cons/c symbol? (or/c string? false/c))))] + [query (listof (cons/c symbol? (or/c string? false/c)))] [fragment (or/c false/c string?)])) (struct path/param ([path (or/c string? (symbols 'up 'same))] [param (listof string?)]))) diff --git a/collects/net/url.rkt b/collects/net/url.rkt index 9398966b85..0a9e41adb3 100644 --- a/collects/net/url.rkt +++ b/collects/net/url.rkt @@ -76,11 +76,7 @@ "")) (combine-path-strings (url-path-absolute? url) path) ;; (if query (sa "?" (uri-encode query)) "") - (if query - (if (null? query) - "?" - (sa "?" (alist->form-urlencoded query))) - "") + (if (null? query) "" (sa "?" (alist->form-urlencoded query))) (if fragment (sa "#" (uri-encode fragment)) "")))) ;; url->default-port : url -> num @@ -263,7 +259,7 @@ ;; transliteration of code in rfc 3986, section 5.2.2 (define (combine-url/relative Base string) (let ([R (string->url string)] - [T (make-url #f #f #f #f #f '() #f #f)]) + [T (make-url #f #f #f #f #f '() '() #f)]) (if (url-scheme R) (begin (set-url-scheme! T (url-scheme R)) @@ -287,7 +283,7 @@ (begin (set-url-path-absolute?! T (url-path-absolute? Base)) (set-url-path! T (url-path Base)) - (if (url-query R) + (if (not (null? (url-query R))) (set-url-query! T (url-query R)) (set-url-query! T (url-query Base)))) (begin @@ -489,7 +485,7 @@ [path (if win-file? (separate-windows-path-strings path) (separate-path-strings path))] - [query (if query (form-urlencoded->alist query) #f)] + [query (if query (form-urlencoded->alist query) '())] [fragment (uri-decode/maybe fragment)]) (make-url scheme user host port abs? path query fragment)))) (cdr (or (regexp-match url-rx str) @@ -578,7 +574,7 @@ (if (eq? base 'relative) accum (loop base accum)))])))]) - (make-url "file" #f "" #f (absolute-path? path) url-path #f #f))) + (make-url "file" #f "" #f (absolute-path? path) url-path '() #f))) (define (url->path url [kind (system-path-convention-type)]) (file://->path url kind)) diff --git a/collects/tests/net/url.rkt b/collects/tests/net/url.rkt index cca25f8d85..1817082d4b 100644 --- a/collects/tests/net/url.rkt +++ b/collects/tests/net/url.rkt @@ -1,6 +1,6 @@ #lang scheme (require net/url tests/eli-tester - (only-in net/uri-codec current-alist-separator-mode uri-encode)) + (only-in net/uri-codec current-alist-separator-mode)) (define (url->vec url) (vector @@ -50,29 +50,29 @@ (current-proxy-servers)) => '(("http" "proxy.com" 3128))) - (test-s->u #(#f #f #f #f #t (#("")) #f #f) + (test-s->u #(#f #f #f #f #t (#("")) () #f) "/") - (test-s->u #(#f #f #f #f #f () #f #f) + (test-s->u #(#f #f #f #f #f () () #f) "") - (test-s->u #("http" #f #f #f #t (#("")) #f #f) + (test-s->u #("http" #f #f #f #t (#("")) () #f) "http:/") - (test-s->u #("http" #f "" #f #t (#("")) #f #f) + (test-s->u #("http" #f "" #f #t (#("")) () #f) "http:///") - (test-s->u #("http" #f "www.drscheme.org" #f #f () #f #f) + (test-s->u #("http" #f "www.drscheme.org" #f #f () () #f) "http://www.drscheme.org") - (test-s->u #("http" #f "www.drscheme.org" #f #t (#("")) #f #f) + (test-s->u #("http" #f "www.drscheme.org" #f #t (#("")) () #f) "http://www.drscheme.org/") - (test-s->u #("http" #f "www.drscheme.org" #f #t (#("a") #("b") #("c")) #f #f) + (test-s->u #("http" #f "www.drscheme.org" #f #t (#("a") #("b") #("c")) () #f) "http://www.drscheme.org/a/b/c") - (test-s->u #("http" "robby" "www.drscheme.org" #f #t (#("a") #("b") #("c")) #f #f) + (test-s->u #("http" "robby" "www.drscheme.org" #f #t (#("a") #("b") #("c")) () #f) "http://robby@www.drscheme.org/a/b/c") - (test-s->u #("http" #f "www.drscheme.org" 8080 #t (#("a") #("b") #("c")) #f #f) + (test-s->u #("http" #f "www.drscheme.org" 8080 #t (#("a") #("b") #("c")) () #f) "http://www.drscheme.org:8080/a/b/c") - (test-s->u #("http" #f "www.drscheme.org" #f #t (#("a") #("b") #("c")) #f "joe") + (test-s->u #("http" #f "www.drscheme.org" #f #t (#("a") #("b") #("c")) () "joe") "http://www.drscheme.org/a/b/c#joe") (test-s->u #("http" #f "www.drscheme.org" #f #t (#("a") #("b") #("c")) ((tim . "")) #f) "http://www.drscheme.org/a/b/c?tim=") @@ -90,53 +90,53 @@ (parameterize ([current-alist-separator-mode 'amp]) (test-s->u #("http" #f "www.drscheme.org" #f #t (#("a") #("b") #("c")) ((tam . "tom") (pam . "pom")) "joe") "http://www.drscheme.org/a/b/c?tam=tom&pam=pom#joe")) - (test-s->u #("http" #f "www.drscheme.org" #f #t (#("a") #("b") #("c" "b")) #f #f) + (test-s->u #("http" #f "www.drscheme.org" #f #t (#("a") #("b") #("c" "b")) () #f) "http://www.drscheme.org/a/b/c;b") - (test-s->u #("http" #f "www.drscheme.org" #f #t (#("a" "x") #("b") #("c" "b")) #f #f) + (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") ;; test unquoting for % (test-s->u #("http" #f "www.drscheme.org" #f #t (#("a") #("b") #("c")) ((ti#m . "")) "jo e") "http://www.drscheme.org/a/b/c?ti%23m=#jo%20e") - (test-s->u #("http" #f "www.drscheme.org" #f #t (#("a " " a") #(" b ") #(" c ")) #f #f) + (test-s->u #("http" #f "www.drscheme.org" #f #t (#("a " " a") #(" b ") #(" c ")) () #f) "http://www.drscheme.org/a%20;%20a/%20b%20/%20c%20") - (test-s->u #("http" "robb y" "www.drscheme.org" #f #t (#("")) #f #f) + (test-s->u #("http" "robb y" "www.drscheme.org" #f #t (#("")) () #f) "http://robb%20y@www.drscheme.org/") - (test-s->u #("http" #f "www.drscheme.org" #f #t (#("%a") #("b/") #("c")) #f #f) + (test-s->u #("http" #f "www.drscheme.org" #f #t (#("%a") #("b/") #("c")) () #f) "http://www.drscheme.org/%25a/b%2F/c") - (test-s->u #("http" "robby:password" "www.drscheme.org" #f #t (#("")) #f #f) + (test-s->u #("http" "robby:password" "www.drscheme.org" #f #t (#("")) () #f) "http://robby:password@www.drscheme.org/") (test "robby:password" (lambda (x) (url-user (string->url x))) "http://robby%3apassword@www.drscheme.org/") ;; test the characters that need to be encoded in paths vs those that do not need to ;; be encoded in paths - (test-s->u #("http" #f "www.drscheme.org" #f #t (#("a:@!$&'()*+,=z") #("/?#[];") #("")) #f #f) + (test-s->u #("http" #f "www.drscheme.org" #f #t (#("a:@!$&'()*+,=z") #("/?#[];") #("")) () #f) "http://www.drscheme.org/a:@!$&'()*+,=z/%2F%3F%23%5B%5D%3B/") - (test-s->u #("http" #f "www.drscheme.org" #f #t (#(".") #("..") #(same) #(up) #("...") #("abc.def")) #f #f) + (test-s->u #("http" #f "www.drscheme.org" #f #t (#(".") #("..") #(same) #(up) #("...") #("abc.def")) () #f) "http://www.drscheme.org/%2e/%2e%2e/./../.../abc.def") - (test-s->u #("http" #f "www.drscheme.org" #f #t (#("." "") #(".." "") #(same "") #(up "") #("..." "") #("abc.def" "")) #f #f) + (test-s->u #("http" #f "www.drscheme.org" #f #t (#("." "") #(".." "") #(same "") #(up "") #("..." "") #("abc.def" "")) () #f) "http://www.drscheme.org/%2e;/%2e%2e;/.;/..;/...;/abc.def;") ;; test other scheme identifiers - (test-s->u #("blah" #f "www.foo.com" #f #t (#("")) #f #f) + (test-s->u #("blah" #f "www.foo.com" #f #t (#("")) () #f) "blah://www.foo.com/") - (test-s->u #("blah99" #f "www.foo.com" #f #t (#("")) #f #f) + (test-s->u #("blah99" #f "www.foo.com" #f #t (#("")) () #f) "blah99://www.foo.com/") - (test-s->u #("blah+" #f "www.foo.com" #f #t (#("")) #f #f) + (test-s->u #("blah+" #f "www.foo.com" #f #t (#("")) () #f) "blah+://www.foo.com/") - (test-s->u #("a+b-c456.d" #f "www.foo.com" #f #t (#("")) #f #f) + (test-s->u #("a+b-c456.d" #f "www.foo.com" #f #t (#("")) () #f) "a+b-c456.d://www.foo.com/") ;; a colon and other junk (`sub-delims') can appear in usernames - (test #("http" "x:!$&'()*+,;=y" "www.drscheme.org" #f #t (#("a")) #f #f) + (test #("http" "x:!$&'()*+,;=y" "www.drscheme.org" #f #t (#("a")) () #f) string->url/vec "http://x:!$&'()*+,;=y@www.drscheme.org/a") ;; a colon and atsign can appear in absolute paths - (test-s->u #(#f #f #f #f #t (#("x:@y") #("z")) #f #f) + (test-s->u #(#f #f #f #f #t (#("x:@y") #("z")) () #f) "/x:@y/z") ;; and in relative paths as long as it's not in the first element - (test-s->u #(#f #f #f #f #f (#("x") #("y:@z")) #f #f) + (test-s->u #(#f #f #f #f #f (#("x") #("y:@z")) () #f) "x/y:@z") ;; test bad schemes @@ -148,38 +148,38 @@ (string->url "a b://www.foo.com/") =error> url-exception?) ;; test file: urls - (test-s->u #("file" #f "" #f #t (#("abc") #("def.html")) #f #f) + (test-s->u #("file" #f "" #f #t (#("abc") #("def.html")) () #f) "file:///abc/def.html") (test (url->string (string->url "file:///abc/def.html")) => "file:///abc/def.html") (parameterize ([file-url-path-convention-type 'unix]) (test (url->string (string->url "file://a/b")) => "file://a/b") - (test-s->u #("file" #f "localhost" #f #t (#("abc") #("def.html")) #f #f) + (test-s->u #("file" #f "localhost" #f #t (#("abc") #("def.html")) () #f) "file://localhost/abc/def.html")) ;; test files: urls with colons, and the different parsing on Windows - (test-s->u #("file" #f "localhost" 123 #t (#("abc") #("def.html")) #f #f) + (test-s->u #("file" #f "localhost" 123 #t (#("abc") #("def.html")) () #f) "file://localhost:123/abc/def.html") (parameterize ([file-url-path-convention-type 'unix]) ;; different parse for file://foo:/... (test (string->url/vec "file://foo:/abc/def.html") - => #("file" #f "foo" #f #t (#("abc") #("def.html")) #f #f))) + => #("file" #f "foo" #f #t (#("abc") #("def.html")) () #f))) (parameterize ([file-url-path-convention-type 'windows]) (test (string->url/vec "file://foo:/abc/def.html") - => #("file" #f "" #f #t (#("foo:") #("abc") #("def.html")) #f #f) + => #("file" #f "" #f #t (#("foo:") #("abc") #("def.html")) () #f) (string->url/vec "file://c:/abc/def.html") - => #("file" #f "" #f #t (#("c:") #("abc") #("def.html")) #f #f) + => #("file" #f "" #f #t (#("c:") #("abc") #("def.html")) () #f) (string->url/vec "file:\\\\d\\c\\abc\\def.html") - => #("file" #f "" #f #t (#("") #("d") #("c") #("abc") #("def.html")) #f #f))) + => #("file" #f "" #f #t (#("") #("d") #("c") #("abc") #("def.html")) () #f))) (parameterize ([file-url-path-convention-type 'unix]) ;; but no effect on http://foo:/... (test (string->url/vec "http://foo:/abc/def.html") - => #("http" #f "foo" #f #t (#("abc") #("def.html")) #f #f))) + => #("http" #f "foo" #f #t (#("abc") #("def.html")) () #f))) (parameterize ([file-url-path-convention-type 'windows]) (test (string->url/vec "http://foo:/abc/def.html") - => #("http" #f "foo" #f #t (#("abc") #("def.html")) #f #f))) + => #("http" #f "foo" #f #t (#("abc") #("def.html")) () #f))) (test (url->string (path->url (bytes->path #"c:\\a\\b" 'windows))) => "file:///c:/a/b" @@ -228,7 +228,7 @@ "HTTP://ROBBY@WWW.DRSCHEME.ORG:80/INDEX.HTML;XXX?T=P#YYY") => #("http" "ROBBY" "www.drscheme.org" 80 #t (#("INDEX.HTML" "XXX")) ((T . "P")) "YYY")) - (test-s->u #("mailto" #f #f #f #f (#("robby@racket-lang.org")) #f #f) + (test-s->u #("mailto" #f #f #f #f (#("robby@racket-lang.org")) () #f) "mailto:robby@racket-lang.org") (test (string->url/vec "http://www.drscheme.org?bar=馨慧") @@ -238,7 +238,7 @@ => #("http" #f "www.drscheme.org" #f #f () ((bár . "é")) #f)) (test-c-u/r "http://www.drscheme.org" - (make-url #f #f #f #f #f '() #f #f) + (make-url #f #f #f #f #f '() '() #f) "http://www.drscheme.org") (test-c-u/r "http://www.drscheme.org" @@ -351,11 +351,6 @@ )) - ;; PR 10497 - (test - (url->string (url #f #f #f #f #f empty empty #f)) => "?" - (url->string (url #f #f #f #f #f empty #f #f)) => "") - ) (provide tests) diff --git a/collects/unstable/net/url.rkt b/collects/unstable/net/url.rkt index 868dfaabb7..03344fc689 100644 --- a/collects/unstable/net/url.rkt +++ b/collects/unstable/net/url.rkt @@ -20,7 +20,7 @@ (url-port in-url) (url-path-absolute? in-url) new-path - #f + empty (url-fragment in-url)))) ;; Eli: if it also removes the query, this it's a bad name, and it's ;; questionable whether it is general enough. Why not make it into a diff --git a/collects/web-server/default-web-root/htdocs/lang-servlets/add01.rkt b/collects/web-server/default-web-root/htdocs/lang-servlets/add01.rkt index 5dedf88a00..d706449cbd 100644 --- a/collects/web-server/default-web-root/htdocs/lang-servlets/add01.rkt +++ b/collects/web-server/default-web-root/htdocs/lang-servlets/add01.rkt @@ -8,7 +8,7 @@ (let* ([uri (request-uri req)] [qry (url-query uri)]) (cond - [(and qry (assoc 'second qry)) + [(assoc 'second qry) => (lambda (a-pair) (response/xexpr `(html (head (title "Answer Page")) @@ -17,7 +17,7 @@ (p ,(format "The answer is: ~a" (+ (string->number (cdr a-pair)) (string->number (cdr (assoc 'first qry))))))))))] - [(and qry (assoc 'first qry)) + [(assoc 'first qry) => (lambda (a-pair) (response/xexpr `(html (head (title "Second Page")) diff --git a/collects/web-server/dispatch/syntax.rkt b/collects/web-server/dispatch/syntax.rkt index c40428c27b..35d4e83513 100644 --- a/collects/web-server/dispatch/syntax.rkt +++ b/collects/web-server/dispatch/syntax.rkt @@ -16,7 +16,7 @@ (list (make-path/param "" empty)) (map (lambda (s) (make-path/param s empty)) strlist)) - #f #f))) + empty #f))) (define-syntax (dispatch-case stx) (syntax-case stx (else) diff --git a/collects/web-server/http/request.rkt b/collects/web-server/http/request.rkt index c5e193b2b2..460fc103bc 100644 --- a/collects/web-server/http/request.rkt +++ b/collects/web-server/http/request.rkt @@ -177,7 +177,7 @@ (make-binding:form (string->bytes/utf-8 (symbol->string k)) (string->bytes/utf-8 v)) #f)]) - (or (url-query uri) empty)))) + (url-query uri)))) #f)] [(bytes-ci=? #"POST" meth) (local