Repository: MarketSquare/robotframework-requests

Issue:
Breaking change with url partially defined in Create Session and * On Session keywords
Like described in this comment: https://github.com/MarketSquare/robotframework-requests/issues/313#issuecomment-823374633 
```
Create Session sess https://mydomain.com/dev
GET On Session sess /test
```

This case is not working as previously.
Solution is to remove / from `test` and append to `dev/` but this can be considered a breaking change.

Discussion:

Patch:
diff --git a/.gitignore b/.gitignore
index 4dd337a..ea232d3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,6 +23,7 @@ lib/
 test.py
 bin/
 src/robotframework_requests.egg-info/
+.pytest_cache/*
 
 # ignore virtuvalenv
 venv/*
diff --git a/README.md b/README.md
index f56537b..9e0b0d9 100644
--- a/README.md
+++ b/README.md
@@ -18,13 +18,13 @@ Library               RequestsLibrary
 
 *** Test Cases ***
 
-Quick Get Request
+Quick Get Request Test
     ${response}=    GET  https://www.google.com
 
 Quick Get Request With Parameters Test
     ${response}=    GET  https://www.google.com/search  params=query=ciao  expected_status=200
 
-Quick Get A JSON Body
+Quick Get A JSON Body Test
     ${response}=    GET  https://jsonplaceholder.typicode.com/posts/1
     Should Be Equal As Strings    1  ${response.json()}[id]
 ```
diff --git a/src/RequestsLibrary/RequestsKeywords.py b/src/RequestsLibrary/RequestsKeywords.py
index 4d932df..290abf3 100644
--- a/src/RequestsLibrary/RequestsKeywords.py
+++ b/src/RequestsLibrary/RequestsKeywords.py
@@ -35,7 +35,7 @@ class RequestsKeywords(object):
         self._capture_output()
 
         resp = method_function(
-            self._get_url(session, uri),
+            self._merge_url(session, uri),
             timeout=self._get_timeout(kwargs.pop('timeout', None)),
             cookies=kwargs.pop('cookies', self.cookies),
             **kwargs)
@@ -53,15 +53,22 @@ class RequestsKeywords(object):
 
         return resp
 
+    
     @staticmethod
-    def _get_url(session, uri):
+    def _merge_url(session, uri):
         """
-        Helper method to get the full url
+        Helper method that join session url and request url.
+        It relies on urljoin that handles quite good join urls and multiple /
+        but has some counter intuitive behaviours if you join uri starting with /
+        It handles also override in case a full url (http://etc) is passed as uri.
         """
+        base = ''
         if session:
             base = session.url
-        else:
-            base = ''
+        if session and uri and not session.url.endswith('/'):
+            base = session.url + '/'
+        if session and uri and uri.startswith('/'):
+            uri = uri[1:]
         url = urljoin(base, uri)
         return url
 
diff --git a/src/RequestsLibrary/__init__.py b/src/RequestsLibrary/__init__.py
index 5e7e37a..c986205 100644
--- a/src/RequestsLibrary/__init__.py
+++ b/src/RequestsLibrary/__init__.py
@@ -32,13 +32,13 @@ class RequestsLibrary(RequestsOnSessionKeywords, DeprecatedKeywords):
         |   Library               RequestsLibrary
         |
         |   *** Test Cases ***
-        |   Quick Get Request
+        |   Quick Get Request Test
         |       ${response}=    GET  https://www.google.com
         |
         |   Quick Get Request With Parameters Test
         |       ${response}=    GET  https://www.google.com/search  params=query=ciao  expected_status=200
         |
-        |   Quick Get A JSON Body
+        |   Quick Get A JSON Body Test
         |       ${response}=    GET  https://jsonplaceholder.typicode.com/posts/1
         |       Should Be Equal As Strings    1  ${response.json()}[id]
 
diff --git a/src/RequestsLibrary/version.py b/src/RequestsLibrary/version.py
index e90ccf6..1f867ad 100644
--- a/src/RequestsLibrary/version.py
+++ b/src/RequestsLibrary/version.py
@@ -1,1 +1,1 @@
-VERSION = '0.9'
+VERSION = '0.9.1'


Test patch:
diff --git a/utests/test_RequestsKeywords.py b/utests/test_RequestsKeywords.py
index c4b4c84..65b0bda 100644
--- a/utests/test_RequestsKeywords.py
+++ b/utests/test_RequestsKeywords.py
@@ -19,50 +19,71 @@ def build_mocked_session_keywords(url=''):
     return session, keywords
 
 
-def test_get_url_with_none_session():
+def test_merge_url_with_none_session():
     keywords = RequestsLibrary()
-    url = keywords._get_url(None, 'http://thisisa.url')
+    url = keywords._merge_url(None, 'http://thisisa.url')
     assert url == 'http://thisisa.url'
 
 
-def test_get_url_with_base():
+def test_merge_url_with_session_url_only():
     session, keywords = build_mocked_session_keywords('http://www.domain.com')
-    url = keywords._get_url(session, '')
+    url = keywords._merge_url(session, '')
     assert url == 'http://www.domain.com'
 
 
-def test_get_url_with_base_endpoint():
+def test_merge_url_with_session_url_and_uri_endpoint():
     session, keywords = build_mocked_session_keywords('http://www.domain.com')
-    url = keywords._get_url(session, 'endpoint')
+    url = keywords._merge_url(session, 'endpoint')
     assert url == 'http://www.domain.com/endpoint'
 
 
-def test_get_url_with_base_slash_endpoint_pre():
+def test_merge_url_with_session_url_slash_and_uri_endpoint():
     session, keywords = build_mocked_session_keywords('http://www.domain.com/')
-    url = keywords._get_url(session, 'endpoint')
+    url = keywords._merge_url(session, 'endpoint')
     assert url == 'http://www.domain.com/endpoint'
 
 
-def test_get_url_with_base_slash_endpoint_post():
+def test_merge_url_with_session_url_and_uri_slash_endpoint():
     session, keywords = build_mocked_session_keywords('http://www.domain.com')
-    url = keywords._get_url(session, '/endpoint')
+    url = keywords._merge_url(session, '/endpoint')
     assert url == 'http://www.domain.com/endpoint'
 
 
+# breaking change with 0.8 introduced in 0.9 :( #329
+def test_merge_url_with_session_url_path_and_uri_root_endpoint():
+    session, keywords = build_mocked_session_keywords('http://www.domain.com/path')
+    url = keywords._merge_url(session, '/endpoint')
+    assert url == 'http://www.domain.com/path/endpoint'
+
+
+# breaking change with 0.8 introduced in 0.9 :( #329
+def test_merge_url_with_session_url_path_and_uri_endpoint():
+    session, keywords = build_mocked_session_keywords('http://www.domain.com/path')
+    url = keywords._merge_url(session, 'endpoint')
+    assert url == 'http://www.domain.com/path/endpoint'
+
+
+def test_merge_url_with_session_url_path_slash_and_uri_endpoint():
+    session, keywords = build_mocked_session_keywords('http://www.domain.com/path/')
+    url = keywords._merge_url(session, 'endpoint')
+    assert url == 'http://www.domain.com/path/endpoint'
+
+
 @pytest.mark.skipif(sys.version_info < (3, 0), reason="different urljoin handling of double slash")
-def test_get_url_with_base2trailing_endpoint():
+def test_merge_url_with_session2trailing_and_endpoint():
     session, keywords = build_mocked_session_keywords('http://www.domain.com//')
-    url = keywords._get_url(session, 'endpoint')
+    url = keywords._merge_url(session, 'endpoint')
     assert url == 'http://www.domain.com/endpoint'
 
 
-def test_get_url_with_base_slash_endpoint_2trailing():
+@pytest.mark.skipif(sys.version_info < (3, 0), reason="different urljoin handling of double slash")
+def test_merge_url_with_session_and_slash_endpoint_2trailing():
     session, keywords = build_mocked_session_keywords('http://www.domain.com')
-    url = keywords._get_url(session, '/endpoint//')
-    assert url == 'http://www.domain.com/endpoint//'
+    url = keywords._merge_url(session, '/endpoint//')
+    assert url == 'http://www.domain.com/endpoint/'
 
 
-def test_get_url_with_url_override_base():
+def test_merge_url_with_url_override_base():
     session, keywords = build_mocked_session_keywords('http://www.domain.com')
-    url = keywords._get_url(session, 'https://new.domain.com')
+    url = keywords._merge_url(session, 'https://new.domain.com')
     assert url == 'https://new.domain.com'