ocaml-uri icon indicating copy to clipboard operation
ocaml-uri copied to clipboard

path segment functions

Open dsheets opened this issue 11 years ago • 7 comments
trafficstars

There should be interface functions to operate over path segments and provide the same kind of services that are available to query components.

dsheets avatar Aug 12 '14 13:08 dsheets

That would be useful in ocsigen as well, some kind of segmented_path: string list function.

Drup avatar Apr 06 '15 23:04 Drup

A prime test for this functionality will be the original segment-of-only-%2F of 37771d7c7a223b6302c961e7d96219ef729d1ced. Other segments containing %2F work fine.

dsheets avatar Apr 17 '15 13:04 dsheets

I'm +1 on this. to give an example of the kind of this kind functionality being useful in the real world [1]:

val add_path_to_url :  string list -> string -> string

Would be great to have something like this.

[1] https://github.com/rgrinberg/gapi-ocaml/blob/master/src/gapi/gapiUtils.mli#L19

rgrinberg avatar May 18 '15 03:05 rgrinberg

You can achieve most of that with resolve:

# Uri.(resolve "" (of_string "/foo/bar/") (of_string "baz/quux/"));;
- : Uri.t = /foo/bar/baz/quux
# Uri.(resolve "" (of_string "/foo/bar/") (of_string "/baz/quux"));;
- : Uri.t = /baz/quux
# Uri.(resolve "" (of_string "/foo/bar/") (of_string "../baz/quux"));;
- : Uri.t = /foo/baz/quux
# Uri.(resolve "" (of_string "/foo/bar") (of_string "baz/quux"));;
- : Uri.t = /foo/baz/quux

dsheets avatar May 18 '15 09:05 dsheets

It's a decent workaround for sure. But it's hard to imagine a user discovering it on their own and I thought this ticket was about adding helpers for this.

rgrinberg avatar May 18 '15 16:05 rgrinberg

I do think more needs to be done to make users aware of the power of resolve.

This issue is about exposing the structure of the path component directly as it must be represented internally. Right now, paths clearly have structure but are opaque at the API level. The library should be able to help users more when they want to route HTTP requests or walk directory trees.

dsheets avatar May 18 '15 16:05 dsheets

+1 for this, would be really useful

mseri avatar May 20 '21 19:05 mseri