You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
unfurlLinks and unfurlMedia are boolean values that end up in the $options array. When setting the explicitly to false (to prevent unfurling), they are stripped in the SlackTransport class from the $options array by filter_array, as a boolean false is considdered empty. This results in the key/value not being present in the json that is sent to Slack.
$slack = new Symfony\Component\Notifier\Bridge\Slack\SlackTransport('xoxb-some-token', 'some-channel');
$opts = new \Symfony\Component\Notifier\Bridge\Slack\SlackOptions(['unfurl_links' => false]);
$message = new \Symfony\Component\Notifier\Message\ChatMessage('Test message with a link to https://www.github.com/', $opts);
$slack->send($message);
var_dump($options, filter_array($options))
array(3) {
["unfurl_links"]=>
bool(false)
["channel"]=>
string(17) "some-channel"
["text"]=>
string(35) "Test message with a link to https://www.github.com/'"
}
array(3) {
["channel"]=>
string(17) "some-channel"
["text"]=>
string(35) "Test message with a link to https://www.github.com/'"
}
Possible Solution
Add custom callback to array_filter function that uses empty(), but explicitly keeps boolean false values
Additional Context
No response
The text was updated successfully, but these errors were encountered:
But I assume that this logic is used on other places as well (maybe even other Bridges), and that array_filter without callable might also remove other options (I could imagine there might be cases where you would set a field to a zero int or so).
…(xabbuh)
This PR was merged into the 5.4 branch.
Discussion
----------
[Notifier] keep boolean options when their value is false
| Q | A
| ------------- | ---
| Branch? | 5.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | Fix#57100
| License | MIT
Commits
-------
b664d75 keep boolean options when their value is false
Symfony version(s) affected
7.x, 6.x, 5.x
Description
unfurlLinks and unfurlMedia are boolean values that end up in the $options array. When setting the explicitly to false (to prevent unfurling), they are stripped in the SlackTransport class from the $options array by filter_array, as a boolean false is considdered empty. This results in the key/value not being present in the json that is sent to Slack.
symfony/src/Symfony/Component/Notifier/Bridge/Slack/SlackTransport.php
Line 81 in 1f90bc3
How to reproduce
Send a message:
var_dump($options, filter_array($options))
Possible Solution
Add custom callback to array_filter function that uses empty(), but explicitly keeps boolean false values
Additional Context
No response
The text was updated successfully, but these errors were encountered: