URI.merge/2#4644
Conversation
| iex> URI.merge("http://example.com", "http://google.com")|> to_string | ||
| "http://google.com" | ||
| """ | ||
| def merge(%URI{authority: nil}, %URI{}), do: raise ArgumentError, "You must merge onto an absolute URI" |
There was a problem hiding this comment.
Error messages start with lower case.
|
Thank you @andrewtimberlake. I have added some comments. I also believe we should call this function URI.join. I would expect a function named |
|
@josevalim I believe it is merging all fields as per the RFC which refers to this as a merge. |
|
Right. We need to consider though the meaning "merge" has in Elixir and the meaning it has in the UFC. If we want to call it "merge", then I would recommend us to call it |
|
I understand. I don’t want to belabour the point but we are doing more than just merging the path. URI.merge("http://example.com", "http://google.com") |> to_string == "http://google.com"
URI.merge("http://example.com/foo?a=b", "?c=d") |> to_string == "http://example.com/foo?c=d"
URI.merge("http://example.com/foo?a=b", "") |> to_string == "http://example.com/foo?a=b"From that info, you tell me what you’d like me to name it. |
|
Merge it is. :) |
| "http://google.com" | ||
| """ | ||
| def merge(%URI{authority: nil}, %URI{}), do: raise ArgumentError, "you must merge onto an absolute URI" | ||
| def merge(%URI{}, %URI{scheme: scheme}=rel) when not is_nil(scheme) do |
There was a problem hiding this comment.
Thanks, I’ll update
There was a problem hiding this comment.
I think scheme != nil (instead of not is_nil(scheme)) reads more easily.
|
@andrewtimberlake please ping us when this is ready to go. :) |
| |> Enum.join("/") | ||
| end | ||
|
|
||
| defp remove_dot_segments(list, acc \\ []) |
There was a problem hiding this comment.
I think we can ditch this clause and simply call remove_dot_segments with [] on L#410.
|
@josevalim It’s ready to go if you’re happy. |
Merge a relative path/URI to a base URI as per RFC3986 §5.2
Examples:
…and more