Repository: Cog-Creators/Red-DiscordBot

Issue:
[V3 Alias] New lines don't get passed to target command
# Command bugs

#### Command name
   [p]alias

#### What cog is this command from?
   alias

#### What were you expecting to happen?
   When using an alias, new lines get passed on to the target command.

#### What actually happened?
   It removes the new lines and passes multiple lines as a single line to the target command.

#### How can we reproduce this issue?
   Should be pretty self explanatory, but here's a screencap [dead link]
   Also, although I'm not sure if it matters, the bug occurred on my v3.1.1 bot


Discussion:
I cannot seem to replicate this. Can you check if the output of `!alias show s` has multiple lines? 
Replicable.

Alias seems to be removing line breaks from arguments for cmd
![IMG](https://Moeka.is-a-good-waifu.com/4vxu52V.png)
And here's an example where if the new lines were being stripped, I'd have a syntax error. This does not appear to be an issue with alias
![image](https://user-images.githubusercontent.com/22035876/57978251-7044d700-79d7-11e9-815c-c7ea04b9870c.png)

oh I may have read the issue wrong here. just aliasing the command itself. 1 moment, I'll look a bit more.

I'm pretty sure that I've written a fix for this issue on my fork, but I want to add some corresponding tests to the suite. Does anyone have any thoughts on the best way this could be done? I'm new to this project.

Resolving patch:
diff --git a/redbot/cogs/alias/alias.py b/redbot/cogs/alias/alias.py
--- a/redbot/cogs/alias/alias.py
+++ b/redbot/cogs/alias/alias.py
@@ -150,6 +150,15 @@ async def get_prefix(self, message: discord.Message) -> str:
         raise ValueError("No prefix found.")
 
     async def call_alias(self, message: discord.Message, prefix: str, alias: AliasEntry):
+        new_message = self.translate_alias_message(message, prefix, alias)
+        await self.bot.process_commands(new_message)
+
+    def translate_alias_message(self, message: discord.Message, prefix: str, alias: AliasEntry):
+        """
+        Translates a discord message using an alias
+        for a command to a discord message using the
+        alias' base command.
+        """
         new_message = copy(message)
         try:
             args = alias.get_extra_args_from_alias(message, prefix)
@@ -163,7 +172,8 @@ async def call_alias(self, message: discord.Message, prefix: str, alias: AliasEn
         new_message.content = "{}{} {}".format(
             prefix, command, " ".join(args[trackform.max + 1 :])
         ).strip()
-        await self.bot.process_commands(new_message)
+
+        return new_message
 
     async def paginate_alias_list(
         self, ctx: commands.Context, alias_list: List[AliasEntry]
diff --git a/redbot/cogs/alias/alias_entry.py b/redbot/cogs/alias/alias_entry.py
--- a/redbot/cogs/alias/alias_entry.py
+++ b/redbot/cogs/alias/alias_entry.py
@@ -62,8 +62,7 @@ def get_extra_args_from_alias(self, message: discord.Message, prefix: str) -> st
             word = view.get_quoted_word()
             if len(word) < view.index - prev:
                 word = "".join((view.buffer[prev], word, view.buffer[view.index - 1]))
-            extra.append(word)
-            view.skip_ws()
+            extra.append(word.strip(" "))
         return extra
 
     def to_json(self) -> dict:
diff --git a/redbot/pytest/core.py b/redbot/pytest/core.py
--- a/redbot/pytest/core.py
+++ b/redbot/pytest/core.py
@@ -23,7 +23,9 @@
     "empty_role",
     "empty_user",
     "member_factory",
+    "newline_message",
     "user_factory",
+    "prefix",
     "ctx",
 ]
 
@@ -142,6 +144,18 @@ def empty_message():
     return mock_msg("No content.")
 
 
+@pytest.fixture(scope="module")
+def newline_message():
+    mock_msg = type("", (), {})()
+    mock_msg.content = "!test a\nb\nc"
+    return mock_msg
+
+
+@pytest.fixture(scope="module")
+def prefix():
+    return "!"
+
+
 @pytest.fixture()
 def ctx(empty_member, empty_channel, red):
     mock_ctx = namedtuple("Context", "author guild channel message bot")


Test patch:
diff --git a/tests/cogs/test_alias.py b/tests/cogs/test_alias.py
--- a/tests/cogs/test_alias.py
+++ b/tests/cogs/test_alias.py
@@ -30,6 +30,20 @@ async def test_add_guild_alias(alias, ctx):
     assert alias_obj.name == "test"
 
 
+async def test_translate_alias_message(alias, ctx, newline_message, prefix):
+    await create_test_guild_alias(alias, ctx)
+    alias_obj = await alias._aliases.get_alias(ctx.guild, "test")
+
+    translated_message = alias.translate_alias_message(newline_message, prefix, alias_obj)
+
+    original_content = newline_message.content.split(" ", 1)[1]
+    original_content = original_content.replace(" ", "")
+    new_content = translated_message.content.split(" ", 1)[1]
+    new_content = new_content.replace(" ", "")
+
+    assert new_content == original_content
+
+
 async def test_delete_guild_alias(alias, ctx):
     await create_test_guild_alias(alias, ctx)
     alias_obj = await alias._aliases.get_alias(ctx.guild, "test")