You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2024/09/06 18:03:33 UTC

(couchdb) branch fix-ipv6-url-parsing-in-couchdb created (now 478df466f)

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a change to branch fix-ipv6-url-parsing-in-couchdb
in repository https://gitbox.apache.org/repos/asf/couchdb.git


      at 478df466f Fix bespoke parsing/composing in couch_replicator_auth_session

This branch includes the following new commits:

     new 478df466f Fix bespoke parsing/composing in couch_replicator_auth_session

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(couchdb) 01/01: Fix bespoke parsing/composing in couch_replicator_auth_session

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch fix-ipv6-url-parsing-in-couchdb
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 478df466fe8283b54635cd7951f00494d9484f2f
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Fri Sep 6 14:01:03 2024 -0400

    Fix bespoke parsing/composing in couch_replicator_auth_session
    
    Use the new uri_string:resolve/2 [1] function instead.
    
    This should fix handling for IPv6 addresses.
    
    Fix: #5223
    
    [1] https://www.erlang.org/doc/apps/stdlib/uri_string.html#resolve/2
---
 .../src/couch_replicator_auth_session.erl           | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/src/couch_replicator/src/couch_replicator_auth_session.erl b/src/couch_replicator/src/couch_replicator_auth_session.erl
index 1b290982c..956c85f6f 100644
--- a/src/couch_replicator/src/couch_replicator_auth_session.erl
+++ b/src/couch_replicator/src/couch_replicator_auth_session.erl
@@ -266,20 +266,7 @@ process_auth_failure(Epoch, #state{epoch = Epoch} = State) ->
 
 -spec get_session_url(string()) -> string().
 get_session_url(Url) ->
-    #url{
-        protocol = Proto,
-        host = Host,
-        port = Port
-    } = ibrowse_lib:parse_url(Url),
-    WithPort = lists:concat([Proto, "://", Host, ":", Port]),
-    case lists:prefix(WithPort, Url) of
-        true ->
-            % Explicit port specified in the original url
-            WithPort ++ "/_session";
-        false ->
-            % Implicit proto default port was used
-            lists:concat([Proto, "://", Host, "/_session"])
-    end.
+    uri_string:resolve("/_session", Url).
 
 -spec schedule_refresh(non_neg_integer(), #state{}) -> #state{}.
 schedule_refresh(T, #state{next_refresh = Tc} = State) when T < Tc ->
@@ -518,7 +505,11 @@ get_session_url_test_() ->
             {"http://127.0.0.1/db", "http://127.0.0.1/_session"},
             {"http://host/x/y/z", "http://host/_session"},
             {"http://host:5984/db", "http://host:5984/_session"},
-            {"https://host/db?q=1", "https://host/_session"}
+            {"https://host/db?q=1", "https://host/_session"},
+            {"http://[fdaa:a:d05:a7b:12:eb5a:cc23:2]:5984?q=4", "http://[fdaa:a:d05:a7b:12:eb5a:cc23:2]:5984/_session"},
+            {"http://[fdaa:a:d05:a7b:12:eb5a:cc23:2]?q=2&n=1", "http://[fdaa:a:d05:a7b:12:eb5a:cc23:2]/_session"},
+            {"http://[::1]", "http://[::1]/_session"},
+            {"http://[::1]:1", "http://[::1]:1/_session"}
         ]
     ].