Skip to content

Commit

Permalink
add trailing slash to the end of the url (#1594)
Browse files Browse the repository at this point in the history
* add trailing slash to the end of the url

* removing commented lines

* adding trailing slash to legacy_base_client.py

---------

Co-authored-by: Kazuhiro Sera <[email protected]>
  • Loading branch information
HTSagara and seratch authored Nov 19, 2024
1 parent d1dffb7 commit c82c9a0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions slack_sdk/web/async_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def __init__(
):
self.token = None if token is None else token.strip()
"""A string specifying an `xoxp-*` or `xoxb-*` token."""
if not base_url.endswith("/"):
base_url += "/"
self.base_url = base_url
"""A string representing the Slack API base URL.
Default is `'https://slack.com/api/'`."""
Expand Down
2 changes: 2 additions & 0 deletions slack_sdk/web/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def __init__(
):
self.token = None if token is None else token.strip()
"""A string specifying an `xoxp-*` or `xoxb-*` token."""
if not base_url.endswith("/"):
base_url += "/"
self.base_url = base_url
"""A string representing the Slack API base URL.
Default is `'https://slack.com/api/'`."""
Expand Down
2 changes: 2 additions & 0 deletions slack_sdk/web/legacy_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def __init__(
):
self.token = None if token is None else token.strip()
"""A string specifying an `xoxp-*` or `xoxb-*` token."""
if not base_url.endswith("/"):
base_url += "/"
self.base_url = base_url
"""A string representing the Slack API base URL.
Default is `'https://slack.com/api/'`."""
Expand Down
8 changes: 8 additions & 0 deletions tests/slack_sdk/web/test_web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,11 @@ def test_user_auth_blocks(self):
user_auth_blocks=[DividerBlock(), DividerBlock()],
)
self.assertIsNone(new_message.get("error"))

def test_base_url_appends_trailing_slash_issue_15141(self):
client = self.client
self.assertEqual(client.base_url, "http://localhost:8888/")

def test_base_url_preserves_trailing_slash_issue_15141(self):
client = WebClient(base_url="http://localhost:8888/")
self.assertEqual(client.base_url, "http://localhost:8888/")

0 comments on commit c82c9a0

Please sign in to comment.