1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00

rename string->uri and uri->string.

* module/web/uri.scm (string->uri, uri->string): Rename from parse-uri
  and unparse-uri.

* test-suite/tests/web-uri.test:
* module/web/http.scm: All callers changed.
This commit is contained in:
Andy Wingo 2010-12-31 12:44:11 -05:00
parent b3f9444892
commit 8745c33afb
3 changed files with 24 additions and 24 deletions

View file

@ -628,7 +628,7 @@ ordered alist."
(display (date->string date "~a, ~d ~b ~Y ~H:~M:~S GMT") port)) (display (date->string date "~a, ~d ~b ~Y ~H:~M:~S GMT") port))
(define (write-uri uri port) (define (write-uri uri port)
(display (unparse-uri uri) port)) (display (uri->string uri) port))
(define (parse-entity-tag val) (define (parse-entity-tag val)
(if (string-prefix? "W/" val) (if (string-prefix? "W/" val)
@ -751,7 +751,7 @@ not have to have a scheme or host name. The result is a URI object."
#:query (and q (substring str (1+ q) (or f end))) #:query (and q (substring str (1+ q) (or f end)))
#:fragment (and f (substring str (1+ f) end))))) #:fragment (and f (substring str (1+ f) end)))))
(else (else
(or (parse-uri (substring str start end)) (or (string->uri (substring str start end))
(bad-request "Invalid URI: ~a" (substring str start end)))))) (bad-request "Invalid URI: ~a" (substring str start end))))))
(define (read-request-line port) (define (read-request-line port)
@ -890,7 +890,7 @@ phrase\"."
((_ sym name) ((_ sym name)
(declare-header sym (declare-header sym
name name
(lambda (str) (or (parse-uri str) (bad-header-component 'uri str))) (lambda (str) (or (string->uri str) (bad-header-component 'uri str)))
uri? uri?
write-uri)))) write-uri))))

View file

@ -37,7 +37,7 @@
build-uri build-uri
declare-default-port! declare-default-port!
parse-uri unparse-uri string->uri uri->string
uri-decode uri-encode uri-decode uri-encode
split-and-decode-uri-path split-and-decode-uri-path
encode-and-join-uri-path)) encode-and-join-uri-path))
@ -160,7 +160,7 @@ consistency checks to make sure that the constructed URI is valid."
(define uri-regexp (define uri-regexp
(make-regexp uri-pat)) (make-regexp uri-pat))
(define (parse-uri string) (define (string->uri string)
"Parse @var{string} into a URI object. Returns @code{#f} if the string "Parse @var{string} into a URI object. Returns @code{#f} if the string
could not be parsed." could not be parsed."
(% (let ((m (regexp-exec uri-regexp string))) (% (let ((m (regexp-exec uri-regexp string)))
@ -197,7 +197,7 @@ printed."
(declare-default-port! 'http 80) (declare-default-port! 'http 80)
(declare-default-port! 'https 443) (declare-default-port! 'https 443)
(define (unparse-uri uri) (define (uri->string uri)
"Serialize @var{uri} to a string." "Serialize @var{uri} to a string."
(let* ((scheme-str (string-append (let* ((scheme-str (string-append
(symbol->string (uri-scheme uri)) ":")) (symbol->string (uri-scheme uri)) ":"))

View file

@ -107,25 +107,25 @@
(build-uri 'http #:userinfo "foo"))) (build-uri 'http #:userinfo "foo")))
(with-test-prefix "parse-uri" (with-test-prefix "string->uri"
(pass-if "ftp:" (pass-if "ftp:"
(uri=? (parse-uri "ftp:") (uri=? (string->uri "ftp:")
#:scheme 'ftp #:scheme 'ftp
#:path "")) #:path ""))
(pass-if "ftp:foo" (pass-if "ftp:foo"
(uri=? (parse-uri "ftp:foo") (uri=? (string->uri "ftp:foo")
#:scheme 'ftp #:scheme 'ftp
#:path "foo")) #:path "foo"))
(pass-if "ftp://foo/bar" (pass-if "ftp://foo/bar"
(uri=? (parse-uri "ftp://foo/bar") (uri=? (string->uri "ftp://foo/bar")
#:scheme 'ftp #:scheme 'ftp
#:host "foo" #:host "foo"
#:path "/bar")) #:path "/bar"))
(pass-if "ftp://foo@bar:22/baz" (pass-if "ftp://foo@bar:22/baz"
(uri=? (parse-uri "ftp://foo@bar:22/baz") (uri=? (string->uri "ftp://foo@bar:22/baz")
#:scheme 'ftp #:scheme 'ftp
#:userinfo "foo" #:userinfo "foo"
#:host "bar" #:host "bar"
@ -133,49 +133,49 @@
#:path "/baz")) #:path "/baz"))
(pass-if "http://bad.host.1" (pass-if "http://bad.host.1"
(not (parse-uri "http://bad.host.1"))) (not (string->uri "http://bad.host.1")))
(pass-if "http://foo:" (pass-if "http://foo:"
(uri=? (parse-uri "http://foo:") (uri=? (string->uri "http://foo:")
#:scheme 'http #:host "foo" #:path "")) #:scheme 'http #:host "foo" #:path ""))
(pass-if "http://foo:/" (pass-if "http://foo:/"
(uri=? (parse-uri "http://foo:/") (uri=? (string->uri "http://foo:/")
#:scheme 'http #:host "foo" #:path "/")) #:scheme 'http #:host "foo" #:path "/"))
(pass-if "http://foo:not-a-port" (pass-if "http://foo:not-a-port"
(not (parse-uri "http://foo:not-a-port"))) (not (string->uri "http://foo:not-a-port")))
(pass-if "http://:10" (pass-if "http://:10"
(not (parse-uri "http://:10"))) (not (string->uri "http://:10")))
(pass-if "http://foo@" (pass-if "http://foo@"
(not (parse-uri "http://foo@")))) (not (string->uri "http://foo@"))))
(with-test-prefix "unparse-uri" (with-test-prefix "uri->string"
(pass-if "ftp:" (pass-if "ftp:"
(equal? "ftp:" (equal? "ftp:"
(unparse-uri (parse-uri "ftp:")))) (uri->string (string->uri "ftp:"))))
(pass-if "ftp:foo" (pass-if "ftp:foo"
(equal? "ftp:foo" (equal? "ftp:foo"
(unparse-uri (parse-uri "ftp:foo")))) (uri->string (string->uri "ftp:foo"))))
(pass-if "ftp://foo/bar" (pass-if "ftp://foo/bar"
(equal? "ftp://foo/bar" (equal? "ftp://foo/bar"
(unparse-uri (parse-uri "ftp://foo/bar")))) (uri->string (string->uri "ftp://foo/bar"))))
(pass-if "ftp://foo@bar:22/baz" (pass-if "ftp://foo@bar:22/baz"
(equal? "ftp://foo@bar:22/baz" (equal? "ftp://foo@bar:22/baz"
(unparse-uri (parse-uri "ftp://foo@bar:22/baz")))) (uri->string (string->uri "ftp://foo@bar:22/baz"))))
(pass-if "http://foo:" (pass-if "http://foo:"
(equal? "http://foo" (equal? "http://foo"
(unparse-uri (parse-uri "http://foo:")))) (uri->string (string->uri "http://foo:"))))
(pass-if "http://foo:/" (pass-if "http://foo:/"
(equal? "http://foo/" (equal? "http://foo/"
(unparse-uri (parse-uri "http://foo:/"))))) (uri->string (string->uri "http://foo:/")))))
(with-test-prefix "decode" (with-test-prefix "decode"
(pass-if (equal? "foo bar" (uri-decode "foo%20bar")))) (pass-if (equal? "foo bar" (uri-decode "foo%20bar"))))