Skip to content

replace kwargs double backslash for multiline messages #294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions rocketchat_API/APISections/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def call_api_get(self, method, api_path=None, **kwargs):
)

def call_api_post(self, method, files=None, use_json=None, **kwargs):
if "text" in kwargs:
Copy link
Owner

@jadolg jadolg Mar 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please extract this into a separate function that sanitizes the text and add a comment/docstring with what the purpose of it is.
It'll make it easier to keep track of it in the future.
I'd also like to see this tested if possible.
Eg: in

def test_chat_post_update_delete_message(logged_rocket):
include some of these characters and check that the posted message has them by retrieving it.
Or create a new test for this purpose altogether.
A better place to place this cleanup could be the chat_post_message function itself since text is not used anywhere else.
Another use I could think of is when text is used in attachments like what we do here:
{"color": "#ff0000", "text": "there"},

That use-case would not be taken into account.

kwargs["text"] = kwargs["text"].replace('\\n', '\n')
kwargs["text"] = kwargs["text"].replace('\\r', '\r')
kwargs["text"] = kwargs["text"].replace('\\t', '\t')
kwargs["text"] = kwargs["text"].replace('\\b', '\b')
kwargs["text"] = kwargs["text"].replace('\\f', '\f')
reduced_args = self.__reduce_kwargs(kwargs)
# Since pass is a reserved word in Python it has to be injected on the request dict
# Some methods use pass (users.register) and others password (users.create)
Expand Down
Loading