widgets: Fix bug where a new line right after /todo broke rendering.

When there was no space right after `/todo` but there was content on a
new line, the message would be rendered plainly, not as a todo widget.
This was because we split on only the space character to then check if
the first token was a valid widget.

Now we split on both spaces and newlines to extract the widget name,
irrespective of whether it is followed by a space or a newline. This
results in the message being rendered as a todo widget as expected.
This commit is contained in:
N-Shar-ma 2023-09-05 22:55:40 +05:30 committed by Tim Abbott
parent 61bc10ca01
commit 8c91c91d86
1 changed files with 1 additions and 1 deletions

View File

@ -8,7 +8,7 @@ from zerver.models import Message, SubMessage
def get_widget_data(content: str) -> Tuple[Optional[str], Optional[str]]:
valid_widget_types = ["poll", "todo"]
tokens = content.split(" ")
tokens = re.split(r"\s+|\n+", content)
# tokens[0] will always exist
if tokens[0].startswith("/"):