Skip to content

Commit 8d6da91

Browse files
authored
Merge pull request #176 from last-genius/add-path-unencoded
Add path_unencoded function
2 parents 60fce85 + 89e0b11 commit 8d6da91

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/uri.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,12 @@ module Path = struct
438438
) "" buf p;
439439
Pct.cast_encoded (Buffer.contents buf)
440440

441+
let decoded_of_path p =
442+
let len = List.fold_left (fun c tok -> String.length tok + c) 0 p in
443+
let buf = Buffer.create len in
444+
iter_concat (fun buf s -> Buffer.add_string buf s) "" buf p;
445+
Pct.cast_decoded (Buffer.contents buf)
446+
441447
(* Subroutine for resolve <http://tools.ietf.org/html/rfc3986#section-5.2.3> *)
442448
let merge bhost bpath relpath =
443449
match bhost, List.rev bpath with
@@ -448,6 +454,7 @@ end
448454

449455
let path_of_encoded = Path.path_of_encoded
450456
let encoded_of_path ?scheme ~component = Path.encoded_of_path ?scheme ~component
457+
let decoded_of_path = Path.decoded_of_path
451458

452459
(* Query string handling, to and from an assoc list of key/values *)
453460
module Query = struct
@@ -754,6 +761,8 @@ let with_path uri path =
754761
| None, _ | Some _, "/"::_ | Some _, [] -> { uri with path=path }
755762
| Some _, _ -> { uri with path="/"::path }
756763

764+
let path_unencoded uri = Pct.uncast_decoded (decoded_of_path uri.path)
765+
757766
let fragment uri = get_decoded_opt uri.fragment
758767
let with_fragment uri =
759768
function

lib/uri.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ val path : ?pct_encoder:pct_encoder -> t -> string
211211
(** Get the encoded path and query components of a URI *)
212212
val path_and_query : t -> string
213213

214+
(** Get the unencoded path component of a URI *)
215+
val path_unencoded : t -> string
216+
214217
(** Replace the path URI with the supplied encoded path.
215218
If a host is present in the supplied URI, the path is made absolute but not
216219
resolved. If the path is empty, the path component is removed.

0 commit comments

Comments
 (0)