Skip to content

Commit

Permalink
When resolving URI inherit userinfo from the base URI
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCBaH authored and vbmithr committed Jan 18, 2018
1 parent 220e5ae commit 184eaf3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/uri.ml
Original file line number Diff line number Diff line change
Expand Up @@ -865,13 +865,15 @@ let resolve schem base uri =
| Some scheme -> scheme
)) in
normalize schem
Path.(match scheme uri, host uri with
| Some _, _ ->
Path.(match scheme uri, userinfo uri, host uri with
| Some _, _, _ ->
{uri with path=remove_dot_segments uri.path}
| None, Some _ ->
| None, Some _, _
| None, _, Some _ ->
{uri with scheme=base.scheme; path=remove_dot_segments uri.path}
| None, None ->
let uri = {uri with scheme=base.scheme; host=base.host; port=base.port} in
| None, None, None ->
let uri = {uri with scheme=base.scheme; userinfo=base.userinfo;
host=base.host; port=base.port} in
let path_str = path uri in
if path_str=""
then { uri with
Expand Down
20 changes: 20 additions & 0 deletions lib_test/test_runner.ml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,25 @@ let test_rel_rel_res =
res >:: test
) uri_rel_rel_res

let userinfo_res = [
"http://user:[email protected]/foo",
["bar", "http://user:[email protected]/bar";
"/", "http://user:[email protected]/";
"http://boo:[email protected]/foo", "http://boo:[email protected]/foo";
]
]

let test_userinfo_res =
userinfo_res |> List.map (fun (base,tests) ->
let base = Uri.of_string base in
List.map (fun (uri,res) ->
let uri = Uri.of_string uri in
let test () = assert_equal ~printer:(fun l -> l)
res (Uri.to_string (Uri.resolve "" base uri)) in
res >::test
) tests
) |> List.fold_left List.rev_append []

let generic_uri_norm = [
"HTTP://example.com/", "http://example.com/";
"http://example.com/%3a%3f", "http://example.com/:%3F";
Expand Down Expand Up @@ -671,6 +690,7 @@ let _ =
@ test_rel_res
@ test_file_rel_res
@ test_rel_rel_res
@ test_userinfo_res
@ test_rel_empty_path_res
@ test_generic_uri_norm
@ test_rel_id
Expand Down

0 comments on commit 184eaf3

Please sign in to comment.