Add failing test for relative url starting with //#168
Open
reynir wants to merge 1 commit intomirage:mainfrom
Open
Add failing test for relative url starting with //#168reynir wants to merge 1 commit intomirage:mainfrom
reynir wants to merge 1 commit intomirage:mainfrom
Conversation
bc13380 to
171c807
Compare
Member
Member
|
A possible fix from @reynir: diff --git a/lib/uri.ml b/lib/uri.ml
index 7b5af34..a41c3f6 100644
--- a/lib/uri.ml
+++ b/lib/uri.ml
@@ -670,6 +670,10 @@ let to_string ?(pct_encoder=pct_encoder ()) uri =
);
(match uri.path with (* Handle relative paths correctly *)
| [] -> ()
+ | "/" :: "/" :: _ when
+ Option.is_none uri.scheme &&
+ Option.is_none uri.userinfo && Option.is_none uri.host && Option.is_none uri.port ->
+ raise (Invalid_argument "relative URI with leading double slash in path")
| "/"::_ ->
Buffer.add_string buf (Pct.uncast_encoded
(encoded_of_path ?scheme ~component:pct_encoder.path uri.path))
diff --git a/lib_test/test_runner.ml b/lib_test/test_runner.ml
index 29ed1ba..97ee461 100644
--- a/lib_test/test_runner.ml
+++ b/lib_test/test_runner.ml
@@ -684,9 +684,13 @@ let test_make_path_rel_identity =
let path = "//aaa/bbb" in
sprintf "of_string (to_string _) identity:%s" path >:: fun () ->
let u = Uri.make ~path () in
- let u' = Uri.of_string (Uri.to_string u) in
- assert_equal ~printer:Uri.to_string ~cmp:Uri.equal
- u u'
+ match Uri.to_string u with
+ | u_str ->
+ let u' = Uri.of_string u_str in
+ assert_equal ~printer:Uri.to_string ~cmp:Uri.equal
+ u u'
+ | exception Invalid_argument _ ->
+ ()
let compat_uris =
[ "http://\nhost" |
Member
Author
|
It seems a quirk of rfc3986 relative references is that paths starting with an empty segment ( In any case it's an annoying corner case. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See #167.
The naming could be better.
I'm not sure you can present this URL as a string, so maybe
Uri.to_stringshould raiseInvalid_argument _or similar?