[Alias] Aliased commands retain newlines #4656
Merged
+40
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type
Description of the changes
As detailed in issue #2704 when an alias for a command is created, and this alias is passed input, any newlines in the input are stripped. This is reproducible with the [p]say command (an example can be seen in the issue documentation).
To fix this, I altered the method get_extra_args_from_alias() in redbot/cogs/alias/alias_entry.py to not skip whitespace in between arguments, maintaining newlines if they exist. When these arguments are then formatted into the content of the message that is passed along to the bot, whitespace is not added back in. This should have the effect of better maintaining the passed message, while still allowing customized parameters to be inserted into the input.
I also added a test case for this issue to tests/cogs/test_alias.py. This required the splitting up of the call_alias in redbot/cogs/alias/alias.py into two functions, in order to return a value that could be tested. It also required the creation of two new fixtures in redbot/pytest/core.py, newline_message and prefix. In the case that more tests are eventually added to test_alias, these might prove useful.
I submitted an earlier PR here: #4632, but accidentally modified the commits. This PR incorporates the feedback given to me there, and should avoid interfering with alias parameter functionality.
Fixes #2704