sm00th / bitlbee-discord

Bitlbee plugin for Discord (http://discordapp.com)
GNU General Public License v2.0
290 stars 27 forks source link

Make server_prefix_len truncate by utf8 characters instead of bytes #86

Closed dequis closed 7 years ago

dequis commented 7 years ago

Fixes issues with invalid utf8 in servers that start their names with unicode characters (like emoji)

Oddly enough there's no glib function for this, and bitlbee's truncate_utf8() does the opposite of what we need to do here (truncates by bytes instead of characters and ensures those bytes are valid utf8)


Fixes #85

I should probably figure out what to do to avoid writing invalid utf8 to the config in the first place (like some sort of write-time validation? but what can i do if it's not valid?), but that's harder than fixing this side.

EionRobb commented 7 years ago

Oddly enough there's no glib function for this

g_utf8_substring()?

dequis commented 7 years ago

g_utf8_substring() is available since 2.30 (somewhat above the current requirements i'd like to have) and doesn't check length before truncating, which is risky. I got the idea of using g_utf8_offset_to_pointer() from there though.