[3.0] Keep Stringable arguments instead of dropping them - #9409
Open
albertlast wants to merge 1 commit into
Open
[3.0] Keep Stringable arguments instead of dropping them#9409albertlast wants to merge 1 commit into
albertlast wants to merge 1 commit into
Conversation
formatMessage() hands its arguments to intl as
->format(array_filter($args, 'is_scalar'))
which throws away objects. That is right for an array or a plain object,
which intl cannot use, but a Stringable converts perfectly well, and dropping
it means the argument never arrives and ICU leaves the placeholder sitting in
the output.
The member list is where this shows: Admin -> Members lists an SMF\IP object
for member_ip, so the IP column rendered the literal text {member_ip}, inside
a link to ?action=trackip;searchip={member_ip}. It now reads 172.19.0.1 and
links to that address.
Stringables are converted before the MessageFormat escaping just above, so
one containing a brace or an apostrophe is protected the same as any other
string, and the non-intl fallback path gets the same value.
Signed-off-by: Mathias Papenbrock <mathiaspapealbert@hotmail.com>
Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Admin → Members prints the literal text
{member_ip}in the IP column, inside a link to?action=trackip;searchip={member_ip}.Localization\MessageFormatter::formatMessage()hands its arguments to intl like this:array_filter($args, 'is_scalar')throws away every object. That is the right call for an array or a plain object — intl fatals onstdClasswith "could not be converted to string" — but aStringableconverts perfectly well. Dropping it means the argument never arrives, and ICU leaves the placeholder in the output rather than substituting anything.Actions/Admin/Members.php::list_getMembers()puts anSMF\IPobject in the row:and
SMF\IP implements \Stringable. So the column'sformat_textnever got its value.Stringables are now converted to strings just before the MessageFormat escaping that already runs over string arguments, so one containing
{,}or'is protected the same as any other string, and the non-intl fallback path further down gets the same value.Checked
On the running forum, Admin → Members:
Ten pages re-rendered afterwards — board index, message index, stats, member list, recent, admin home, member list, error log, moderation centre, profile — no fatals and no other change.
The alternative
Members.phpcould instead declare the column as'member_ip' => true, which makesItemListdohtmlspecialchars((string) $value)before formatting. That fixes this one column and leaves the trap in place for the nextStringablesomeone passes, so I fixed the formatter. Happy to do it the other way if you would rather keepformatMessage()strict.Found by sweeping every rendered page of a stock forum for unsubstituted
{placeholders}, alongside #9407 and #9408.Issues References (Fixes|Related|Closes)
Related to #7933