xapi-project / xen-api

The Xapi Project's XenAPI Server
http://xenproject.org/developers/teams/xapi.html
Other
342 stars 282 forks source link

Remove parse_uri, switch to using Uri module instead #5775

Closed last-genius closed 4 days ago

last-genius commented 4 days ago

Follows on from #5726.

Introduces a fix to a bug noticed by a failing quicktest (CA-395184):

diff --git a/ocaml/libs/http-lib/http_svr.ml b/ocaml/libs/http-lib/http_svr.ml
index 2950bb3f7..c27f59a79 100644
--- a/ocaml/libs/http-lib/http_svr.ml
+++ b/ocaml/libs/http-lib/http_svr.ml
@@ -375,7 +375,7 @@ let request_of_bio_exn ~proxy_seen ~read_timeout ~total_timeout ~max_length bio
                  (* Request-Line   = Method SP Request-URI SP HTTP-Version CRLF *)
                  let uri_t = Uri.of_string uri in
                  if uri_t = Uri.empty then raise Http_parse_failure ;
-                 let uri = Uri.path uri_t in
+                 let uri = Uri.path uri_t |> Uri.pct_decode in
                  let query = Uri.query uri_t |> kvlist_flatten in
                  let m = Http.method_t_of_string meth in
                  let version =

Query doesn't need to be percent-decoded, the problem is in Uri.path:

utop # Uri.of_string "/foo?x=<>`&" |> Uri.query;;
- : (string * string list) list = [("x", ["<>`"]); ("", [])]
utop # Uri.of_string "/foo<>`&?x=<>`&" |> Uri.path;;
- : string = "/foo%3C%3E%60&"
utop # Uri.of_string "/foo<>`&?x=<>`&" |> Uri.path |> Uri.pct_decode;;
- : string = "/foo<>`&"

=====

This change passed the BST+BVT test suites

coveralls commented 4 days ago

Coverage Status

coverage: 44.887%. remained the same when pulling e53ce67ad6fe226008f1877bd346461b372a110d on last-genius:private/asultanov/uri-improvement into e61e0acc3d04653ce203db316769c66377897869 on xapi-project:master.