net/url: add relative-path->relative-url-string
original commit: e27c51698b
This commit is contained in:
parent
1e1d92d311
commit
e1814d5686
|
@ -194,6 +194,17 @@ Converts @racket[URL], which is assumed to be a @racket["file"] URL,
|
|||
to a path.}
|
||||
|
||||
|
||||
@defproc[(relative-path->relative-url-string [path (and/c (or/c path-string? path-for-some-system?)
|
||||
relative-path?)])
|
||||
string?]{
|
||||
|
||||
Converts @racket[path] to a string that parses as a relative URL (with
|
||||
forward slashes). Each element of @racket[path] is an element of the
|
||||
resulting URL path, and the string form of each element is encoded as
|
||||
needed. If @racket[path] is syntactically a directory, then the resulting
|
||||
URL ends with @litchar{/}.}
|
||||
|
||||
|
||||
@defparam[file-url-path-convention-type kind (or/c 'unix 'windows)]{
|
||||
|
||||
Determines the default conversion to and from strings for
|
||||
|
|
|
@ -377,6 +377,21 @@
|
|||
|
||||
))
|
||||
|
||||
(test (relative-path->relative-url-string "a")
|
||||
=> "a")
|
||||
(test (relative-path->relative-url-string "a/")
|
||||
=> "a/")
|
||||
(test (relative-path->relative-url-string "a/b")
|
||||
=> "a/b")
|
||||
(test (relative-path->relative-url-string (build-path "a" 'up "b"))
|
||||
=> "a/../b")
|
||||
(test (relative-path->relative-url-string (build-path "a" 'same "b" 'up))
|
||||
=> "a/./b/../")
|
||||
(test (relative-path->relative-url-string (build-path "a&c;" 'same "b"))
|
||||
=> "a%26c%3B/./b")
|
||||
(test (relative-path->relative-url-string (bytes->path '#"\\\\?\\REL\\a\\b/c\\d" 'windows))
|
||||
=> "a/b%2Fc/d")
|
||||
|
||||
)
|
||||
|
||||
(module+ test (require (submod ".." main))) ; for raco test & drdr
|
||||
|
|
Loading…
Reference in New Issue
Block a user