Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Translation] MessageCatalogue::add() accepts non-string messages #49894

Closed
rob006 opened this issue Apr 1, 2023 · 0 comments
Closed

[Translation] MessageCatalogue::add() accepts non-string messages #49894

rob006 opened this issue Apr 1, 2023 · 0 comments

Comments

@rob006
Copy link
Contributor

rob006 commented Apr 1, 2023

Symfony version(s) affected

5.4.22

Description

MessageCatalogue::set() expects message to be string, but MessageCatalogue::add() (and the same applies for constructor) does not have any validation for messages array and in practice message could be anything, for example null. This creates inconsistencies, because MessageCatalogue::all() may return these keys with null as value even if MessageCatalogue::has() will return false 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 with null as value, which resulted deprecation warning in Flarum, because they do not expected that MessageCatalogue::all() may return non-string messages (see rob006-software/flarum-ext-last-post-avatar#2).

How to reproduce

$catalogue = new MessageCatalogue('en');
$catalogue->add(['test' => null]);
assert($catalogue->all() === [] || $catalogue->all(['test' => ''])); 

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 in MessageCatalogue::add() would be a good place to do this.

Additional Context

No response

@rob006 rob006 added the Bug label Apr 1, 2023
nicolas-grekas added a commit that referenced this issue May 19, 2023
…r` (rob006)

This PR was merged into the 5.4 branch.

Discussion
----------

[Translation] Fix handling of null messages in `ArrayLoader`

| Q             | A
| ------------- | ---
| Branch?       |  5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #49894
| License       | MIT
| Doc PR        | -

Replaces #50252

Commits
-------

4be2036 [Translation] Fix handling of null messages in `ArrayLoader`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants