When connecting to either TextChatService.MessageReceived or TextChatService.SendingMessage. the TextChatMessage.Text string has any instance of ‘<’ or ‘>’ replaced with ‘& lt;’ or ‘& gt;’, (with the space removed, Discourse automatically converts the text to < or >)
Repro:
Open a new place, be sure TextChatService.ChatVersion is TextChatService.
create a local script in StarterPlayer with the code:
local TCS = game:GetService("TextChatService")
TCS.MessageReceived:Connect(function(textChatMessage: TextChatMessage)
print(textChatMessage.Text)
end)
Type < or > in the chat window, and notice it comes out as ‘& lt;’ or ‘& gt;’
Occurs in Studio and Live Servers
Expected behavior
Intend behavior is to return ‘<’ or ‘>’ when typing a message containing ‘<’ or ‘>’
I’d argue that the current behaviour is better since otherwise you’d need to escape these characters yourself for RichText rendering. The function you list is intended to be used in custom chat UIs to render messages with RichText enabled, so changing this behaviour would break most of those systems. Perhaps a raw, non-escaped version of the text should also be returned, but the current escaped version should continue to be returned.
Posting to confirm that this is not a bug and working as intended. TextChatService will escape <, >, and & to prevent users from using rich text tags to format their messages in UI that has RichText enabled.
There may be a valid story here to have an option to turn off this escaping if a developer wants to make a custom chat that has RichText off, but I havent heard many use cases for that yet.
As the user above pointed out, would be good to have the non formatted version as a property of the message content, I use the text displayed in the chat to be also displayed above the user’s head, and when using “<” or “>” it displays the text that the user would not expect to, I understand this is intended behavior because the RichText is placed in the same property the message text goes, so having a separate property with unmodified text to use in non-richtext TextLabels would help in my use case
I do not use RichText for a majority of my projects, or most of my UI at all. Thus, if I implement a chat system under the guise that it will be applicably the same as how TextChatService filters messages, there will be confusion as to why those symbols are being replaced at all, when RichText is not enabled.
This puts a focus on the developer having to also transceive the user’s messages and replace those replacements as well to fix this issue. This seems a little backwards, given the issue that was meant to be solved.
Please think about making this an option in the future.