Fixed \XF\Mvc\Renderer#renderRedirect broken use of $message

PaulB

Well-known member
Affected version
2.2.3
We were investigating what types \XF\Mvc\Reply#getMessage() can return, since it's not documented in the class itself, and PhpStorm likes to assume that it will always be a string. In first-party code, it's used exclusively by the various implementations of \XF\Mvc\Renderer#renderRedirect. However, there are discrepancies between how different implementations handle it; XML's in particular appears to be broken.
  • Html: ignores the value
  • Json: expects string|\Stringable|\JsonSerializable--can technically handle other types, but the output will be something other than a string
  • Raw: ignores the value
  • Rss: extends Xml, doesn't override renderRedirect
  • Xml: string, despite attempting to use a Phrase if the value isn't truthy
Tracing the code in Xml's renderRedirect:
PHP:
\XF\Util\Xml::createDomElements($rootNode, [
   'status' => $type,
   'url' => $url,
   'message' => (!$message ? \XF::phrase('redirect_changes_saved_successfully') : $message)
]);

createDomElements:
PHP:
self::createDomElement($document, 'message', $message);

createDomElement:
PHP:
$e = $document->createElement('message');
if (is_scalar($message))
{
   $e->appendChild($document->createTextNode($message));
}
else if ($message instanceof \DOMNode)
{
   $e->appendChild($value);
}
return $e;

If $message is a truthy scalar, this code will work correctly; however, if it's a Phrase, it will break, resulting in an empty <message /> node.
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.4).

Change log:
Render phrases presented as $value to XML createDomElement()
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom