[Translation] MessageCatalogue::add()
accepts non-string messages
#49894
Labels
MessageCatalogue::add()
accepts non-string messages
#49894
Symfony version(s) affected
5.4.22
Description
MessageCatalogue::set()
expects message to be string, butMessageCatalogue::add()
(and the same applies for constructor) does not have any validation for messages array and in practice message could be anything, for examplenull
. This creates inconsistencies, becauseMessageCatalogue::all()
may return these keys withnull
as value even ifMessageCatalogue::has()
will returnfalse
for them.In my case loading https://github.com/rob006-software/flarum-ext-last-post-avatar/blob/1ab3d5a5a7b8959f77481e389a1aba08bf97d37f/locale/en.yml resulted
rob006-last-post-avatar.forum
key withnull
as value, which resulted deprecation warning in Flarum, because they do not expected thatMessageCatalogue::all()
may return non-string messages (see rob006-software/flarum-ext-last-post-avatar#2).How to reproduce
Possible Solution
I think that all messages should be cast to string before adding to
MessageCatalogue::$messages
. I case of loading YAML like https://github.com/rob006-software/flarum-ext-last-post-avatar/blob/1ab3d5a5a7b8959f77481e389a1aba08bf97d37f/locale/en.yml I would expect that these null-keys will be completely skipped, but I'm not sure if skipping them inMessageCatalogue::add()
would be a good place to do this.Additional Context
No response
The text was updated successfully, but these errors were encountered: