-
-
Notifications
You must be signed in to change notification settings - Fork 445
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
Clean up chat messages of special line characters prior to sending #3312
Clean up chat messages of special line characters prior to sending #3312
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a thought on the changelog but otherwise the functionality change fixes the issue you have described.
Tested it by adding a command with new lines - without this PR only asd1 sent, with the PR all 3 sent on a single line.
asd1
asd2
asd3
I want that my newlines would be converted to spaces when sending, as it its now. What will I do after this PR? |
user input:
|
Sending a message in chat? Remains the same, feel free to test it yourself if you'd like. Actually that is one thing that I am confused on. Current if you paste and send a message in chat that does have new lines, it behaves as you said. The message is sent and replaces the new lines with spaces. However, when you do the same but instead as a command, it will only send the first line. To be honest I'm not sure why. I looked through it all again too and can't figure out why that's the case. My original thought was to make this change within the Command class. However, I noticed that the change only affects adding new commands or modifying existing ones. |
Turns out this sends the text as raw irc. Here is an example command: |
Wasn't aware of this, is this behavior intended? When I thought I understood the current behavior of sending messages given your example, I'm still uncertain as to why it's behaving as such. My thought as to why is that we know the channel we are in for the first message and sends that fine via the underlying send raw message method. The second line in your example gets sent because it explicitly sends the second line in the raw format as mentioned in #3189 in the first bullet. However, what I'm not grasping is why it's making two individual raw calls when it is one message but with line breaks. I personally couldn't find anywhere that iterates over line breaks and sends a raw call for each. However going back to the whether or not this is intended behavior, I would imagine the answer is no. Right? Not only because it doesn't seem to make perfect sense as to why it should do so, but also because if you paste your same example into the chatbox rather than a command and send it, it sends it raw as intended. |
The problem is that there is just no validation that removes new lines but they are meaningful in IRC. IRC is a text protocol. An IRC message is defined as follows:
All this mumbo-jumbo means that a normal chat message you'd sent to
If you were to add a line break into the text (ie
My example did this:
|
Ah okay, I had no idea how IRC functions. To tackle no validation, what are your thoughts on using a regex to search the message for IRC commands after a new line? If there is, then leave it alone, but if there isn't then replace the new lines with spaces. |
IMO just not letting new lines sneak through to the TwitchIRCServer should be enough, using regex is an overkill, just remove replace CR and LF with spaces. |
That's what we are currently doing and what led me to making this change |
Thanks for your contribution @Infinitay! As a first-time contributor, you can now add yourself to the contributors list that's shown inside the application. To do so, open a new PR where you modify the |
Now we're on commit b4b7450; Changes from upstream we've pulled: - Minor: Clean up chat messages of special line characters prior to sending. (Chatterino#3312) - Bugfix: Fixed `First Message` scrollbar highlights not being disabled. (Chatterino#3325) - Dev: Add GitHub action to test builds without precompiled headers enabled. (Chatterino#3327)
Pull request checklist:
CHANGELOG.md
was updated, if applicableDescription
If you add a command that contains a new line in the message, it does not correctly send the message. It will only send the first line of the command. The issue does not occur if you manually input the message with new lines into the chat box and hit send. This behavior only seems to occur with commands.
For example, if you have a command set to the following (including the new line):
The solution I found was to remove the new line characters from the message. Instead of removing it from the command itself when users add or update a command, it might be best to do so prior to sending the message as done in this PR. Also, I wasn't sure if messages would have a difference between
\n
and\r\n
depending on their OS, so I foundQString::simplified
to be useful as it replaces escape characters with a space. This way ascii arts shouldn't be affected either, and text messages would be more readable too (no added space versus an added space).