stream
stream copied to clipboard
BuddyPress: Uncaught ValueErrror from printf-style messages.
Bug Report
Similar to #1508, the BuddyPress connector (And it appears others, by reading code) are still affected by that..
Uncaught ValueError: Unknown format specifier "D" in wp-content/plugins/stream/classes/class-log.php:127
Stack trace:
#0 wp-content/plugins/stream/classes/class-log.php(127): vsprintf('Unmarked activi...', Array)
#1 [internal function]: WP_Stream\Log->log('buddypress', 'Unmarked activi...', Array, 9894139, 'forums', 'unspammed', 0)
#2 wp-content/plugins/stream/classes/class-connector.php(178): call_user_func_array(Array, Array)
#3 wp-content/plugins/stream/connectors/class-connector-buddypress.php(685): WP_Stream\Connector->log('Unmarked activi...', Array, 123456, 'forums', 'unspammed')
Expected Behavior
The $message passed to Log::log() should be a printf-ready string, instead it's often containing prepared data.
Actual Behavior
https://github.com/xwp/stream/blob/393ab0cb92723bac62a8eff82c2f6462383a1fde/connectors/class-connector-buddypress.php#L678-L689
In the above case, vsprintf( 'Unmarked activity "something 5% Do something"', [ 'id' => ?, 'item_id' => ??, ... ] ) is called, which is obviously wrong.
It appears that a number of connectors are calling log() and passing context to the vsprintf args key, instead of args that should be interpolated into the message.
Here's an example of a correct usage: https://github.com/xwp/stream/blob/393ab0cb92723bac62a8eff82c2f6462383a1fde/connectors/class-connector-users.php#L155-L169
Here's another example of an incorrect usage (That happens to pass, as the first key of the $args happens to be the one wanted) https://github.com/xwp/stream/blob/393ab0cb92723bac62a8eff82c2f6462383a1fde/connectors/class-connector-comments.php#L238-L245
This is a little more prevalent in the plugin than I expected, but appears to mostly not be an issue as it's rare for the $message to contain a % character.