Proposal: URI.merge/2

Skip to first unread message

Andrew Timberlake

unread,
May 18, 2016, 3:21:10 PM5/18/16
to elixir-l...@googlegroups.com
Example:

iex> URI.merge("http://example.com/foo", "/bar") |> to_string
"http://example.com/bar"

iex> URI.parse("http://example.com/foo") |> URI.merge("/bar") |> to_string
"http://example.com/bar"

…and more

I have written the code based on RFC2396 §5.2 and would like to send through a pull request.

Andrew

Onorio Catenacci

unread,
May 18, 2016, 3:59:21 PM5/18/16
to elixir-lang-core
Not that it seems any different in a salient way but it looks like 2396 was superseded by RFC 3986.  I looked at it quickly but didn't see any significant differences but you may just want to double check your implementation to insure it conforms.

--
Onorio

Jon Parise

unread,
May 18, 2016, 8:05:42 PM5/18/16
to elixir-l...@googlegroups.com
A minor piece of feedback, but have you considered naming this URI.join/2?

That would be consistent with similar functions in Python (urlparse.urljoin) and Ruby (URI.join).


Andrew

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/C1FD35C2-B4C6-4701-83AC-F0F1FA656E1D%40andrewtimberlake.com.
For more options, visit https://groups.google.com/d/optout.

Andrew Timberlake

unread,
May 18, 2016, 11:57:21 PM5/18/16
to elixir-l...@googlegroups.com
Thanks for pointing that out, I’ll have a look.

Andrew

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

Andrew Timberlake

unread,
May 19, 2016, 1:03:31 AM5/19/16
to elixir-l...@googlegroups.com
Jon

RFC3986 refers to the process as merging in §5.2
“The pseudocode above refers to a "merge" routine for merging a
   relative-path reference with the path of the base URI”

But, I’m indifferent about the naming.

Andrew

Andrew Timberlake

unread,
May 19, 2016, 1:09:34 AM5/19/16
to elixir-l...@googlegroups.com
I’ve made changes picked up from RFC3986 and submitted a pull request, https://github.com/elixir-lang/elixir/pull/4644

Andrew

Peter Hamilton

unread,
May 19, 2016, 1:35:22 AM5/19/16
to elixir-l...@googlegroups.com
What's missing from Path.join?

iex(1)> Path.join("http://google.com", "/bar")
iex(2)> Path.join("http://google.com/", "/bar")
iex(3)> Path.join("http://google.com/foo", "/bar")
iex(4)> Path.join("http://google.com/foo", "bar")

If something, the new function should definitely be URI.join

Andrew Timberlake

unread,
May 19, 2016, 7:35:15 AM5/19/16
to elixir-l...@googlegroups.com
Just some example differences.


iex> URI.merge("http://google.com", "http://example.com") |> to_string


iex> URI.merge("http://google.com?a=b", "?x=y") |> to_string

There is an active pull request, please add some comments there if you still have some.

Andrew

Onorio Catenacci

unread,
May 19, 2016, 8:38:53 AM5/19/16
to elixir-lang-core
You should look at the RFC he references Peter.  The rules for merging URI's are not quite as straightforward as you would guess.  Looking at the samples in the RFC, it looks like Andrew's gotten his code right and it looks like Path.join would not serve the need.

--
Onorio


--
You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-core/d4oY2p1wFbk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAOMhEnzjo23afXNYZ0ZviJYBmaxMSgJef%3DEsBoXGyq5SFikuPg%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Peter Hamilton

unread,
May 19, 2016, 11:39:46 AM5/19/16
to elixir-lang-core
I see.

merge is a better name than join, since it clearly does something quite different.

Reply all
Reply to author
Forward
0 new messages