Lachee / discord-rpc-csharp

C# custom implementation for Discord Rich Presence. Not deprecated and still available!
MIT License
561 stars 93 forks source link

Strings' max lengths should be not in bytes, but in characters #218

Open maximmax42 opened 1 year ago

maximmax42 commented 1 year ago

Consider this string of 128 Cyrillic letters а: аааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааа Counting in UTF-8 bytes, it's 256 bytes long, and yet, if I replace byte check in the library with a simple length comparison, it works just fine: image

Here's a string that has 64 Cyrillic а's and 64 Latin b's: ааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb Byte length would be 192, but character length is still 128, so it also works just fine: image

I've also tested if other people see the presence with those strings, and they do.

Thought up of another test, Zalgo. Consider this string: GitHub removes Zalgo text so here's a link to the string instead 206 bytes, 110 characters. Under 128 character, so it works: image

Lachee commented 1 year ago

I'll look into this on my end. I will have to verify the API response because when this was first implemented it was byte count.

maximmax42 commented 1 year ago

Yeah, it was probably changed, and it's not mentioned anywhere. Old page for this API still says 128 bytes, but it also says image names can be no more than 32 bytes, which we know isn't true anymore.

maximmax42 commented 1 year ago

Oh and also, API doesn't accept text fields that are exactly 1 character, needs to be 2 or more.

maximmax42 commented 1 year ago

An update: while button labels accept 32 any characters even if it's more than 32 bytes, putting a label with 32+ bytes still causes the whole presence to not show for others.

Discord Moment:tm: