Discord.Net icon indicating copy to clipboard operation
Discord.Net copied to clipboard

[Bug]: CleanContent doesn't sanitize properly text with `>` or `\`

Open JustArchi opened this issue 3 years ago • 3 comments

Check The Docs

  • [X] I double checked the docs and couldn't find any useful information.

Verify Issue Source

  • [X] I verified the issue was caused by Discord.Net.

Check your intents

  • [X] I double checked that I have the required intents.

Description

When accessing IMessage.CleanContent property, which provides sanitized version of Content, it incorrectly strips markdown characters when using literal > character (not a quote), e.g. in <text>.

Discord client screenshot: obraz

My own Discord.Net logs implementation which just records CleanContent to file (along with some other stuff):

2022-02-17 12:45:43|discord-215255099000225792 (Archi): hm, test <test @<test
2022-02-17 12:45:55|discord-215255099000225792 (Archi): I think I found a bug in discord.net again

As you can see, the > character isn't rendered whatsoever, despite not being used as a quote block.

Version

3.3.2

Working Version

This is the first time I've noticed that, so not a regression to me.

Logs

N/A, no exceptions or anything unusual.

Sample

DiscordShardedClient.MessageReceived += static message => {
	Console.WriteLine(message.CleanContent);
			
	return Task.CompletedTask;
};

It should also be reproducible with all other IDiscordClient implementations.

Thank you in advance for your time in regards to this bug report.

JustArchi avatar Feb 17 '22 11:02 JustArchi

It seems that \ character is also stripped, even if it doesn't escape anything.

obraz

2022-02-17 15:56:10|discord-215255099000225792 (Archi): test

JustArchi avatar Feb 17 '22 14:02 JustArchi

cc @emillly-b

quinchs avatar Mar 26 '22 14:03 quinchs

My idea on moving forward with this issue:

Discord.Net probably needs a markdown library if it doesn't use one yet, in one of my projects I've used https://github.com/xoofx/markdig and got very good results with converting markdown to plain text.

Depending on your view whether you already have dependency on such library or not, and whether you want it in core or not, the proper solutions I see are:

  • Accept it into the mainline, probably it can simplify all other places currently using markdown, use the library for stripping markdown tags in regards to this issue.
  • Accept it as a supportive package (independent of core Discord.Net, like Discord.Net.Webhook) which will add extension on IMessage to do the same.

Doing it ourselves, while possible, is probably one of the worse ideas. In regards to me, I'm fine with either - I don't know Discord.Net better to state whether it makes sense in mainline, considering how tightly markdown is connected with discord - it might be, but it's also fine to justify dependency outside of mainline if deemed appropriate.

JustArchi avatar Jun 11 '22 09:06 JustArchi

This issue has been picked up in the planning for v4 in a different issue (#2588) and will do precisely what was suggested. Closing this as it has been mentioned there for future reference.

csmir avatar Feb 09 '23 16:02 csmir