Fixed All redirects to search results should include search query arguments

Xon

Well-known member
Affected version
2.2.12
The current ownership checks assume the search query arguments are always included so the query can be re-run. But this isn't the case and causes various bugs.

Do a member search in a guest session and copy & paste that into a member session, get complete nonsense as search results.
 
The problem appears to be this function;

PHP:
namespace XF\Pub\Route;

class Search
{
   public static function build(&$prefix, array &$route, &$action, &$data, array &$params)
   {
      if ($data instanceof \XF\Entity\Search && $data->search_query)
         {
...
 
I think this would be the fix:
PHP:
class Search
{
   public static function build(
        string &$prefix,
        array &$route,
        string &$action,
               &$data,
        array &$params,
        \XF\Mvc\Router $router
    ): ?\XF\Mvc\RouteBuiltLink
    {
        if ($data instanceof \XF\Entity\Search)
        {
            $params['q'] = $data->search_query;
            $params['t'] = $data->search_type;
            $params['c'] = $data->search_constraints;
            $params['o'] = $data->search_order;
            if ($data->search_grouping)
            {
                $params['g'] = 1;
            }

            $params = array_filter($params, function ($e) {
                // avoid removing pure falsy values, which may include terms we don't want to skip
                return $e !== null && $e !== 0 && $e !== '' && $e !== [];
            });
        }

        return null; // default processing otherwise
    }
}
 
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.13).

Change log:
Always include search query arguments when building search links
There may be a delay before changes are rolled out to the XenForo Community.
 
Top Bottom