Skip to content
This repository has been archived by the owner on Aug 22, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1581 from RasaHQ/strip_whitespace
Browse files Browse the repository at this point in the history
strip surrounding newlines from messages
  • Loading branch information
tmbo committed Jan 16, 2019
2 parents 0c9ac7c + 9049f9a commit 54a8a44
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Added
(as long as the event itself is enabled in the application hosting the bot)
- Added sanitization mechanism for SlackInput that (in its current shape and form)
strips bot's self mentions from messages posted using the said @mentions.

Removed
-------
- support for deprecated intents/entities format
Expand All @@ -48,6 +48,7 @@ Fixed
dispatched messages using ``dispatcher.utter_custom_message``
- re-added missing ``python-engineio`` dependency
- fixed not working examples in ``examples/``
- strip newlins from messages so you don't have something like "\n/restart\n"


[0.12.3] - 2018-12-03
Expand Down
6 changes: 4 additions & 2 deletions rasa_core/channels/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ def __init__(self,
parse_data: Dict[Text, Any] = None,
input_channel: Text = None
) -> None:

self.text = text
if text:
self.text = text.strip()
else:
self.text = text

if output_channel is not None:
self.output_channel = output_channel
Expand Down
8 changes: 8 additions & 0 deletions tests/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,3 +731,11 @@ def test_message(sender, message):
channel = OutputChannel()
channel.send_text_message = test_message
channel.send_custom_message("user", [{'title': 'a', 'subtitle': 'b'}])


def test_newsline_strip():
from rasa_core.channels import UserMessage

message = UserMessage("\n/restart\n")

assert message.text == "/restart"

0 comments on commit 54a8a44

Please sign in to comment.