Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 300003

Invalid twig token variables are added on certain URLs and will crash the site if assertions are enabled

$
0
0

Problem/Motivation

If assert.active is enabled (default PHP behaviour), and you open a view with non-standard parameters, Views will add the invalid parameters as twig tokens, and will fail the assertion later down the line, and throw the following exception:

The website encountered an unexpected error. Please try again later.

AssertionError: Tokens need to be valid Twig variables. in assert() (line 390 of core/modules/views/src/Plugin/views/PluginBase.php).
Drupal\views\Plugin\views\PluginBase->viewsTokenReplace('<a href="{{ view_node }}">{{ type }}</a>', Array) (Line: 1396)
Drupal\views\Plugin\views\field\FieldPluginBase->renderAltered(Array, Array) (Line: 1289)
Drupal\views\Plugin\views\field\FieldPluginBase->renderText(Array) (Line: 1243)
Drupal\views\Plugin\views\field\FieldPluginBase->advancedRender(Object) (Line: 238)
template_preprocess_views_view_field(Array, 'views_view_field', Array)
call_user_func_array('template_preprocess_views_view_field', Array) (Line: 285)
Drupal\Core\Theme\ThemeManager->render('views_view_field', Array) (Line: 433)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 1788)
Drupal\views\Plugin\views\field\FieldPluginBase->theme(Object) (Line: 758)
Drupal\views\Plugin\views\style\StylePluginBase->elementPreRenderRow(Array)

We should only add valid twig tokens in the list.

Steps to reproduce

PHP assertions might be on by default, but if they aren't, you may enforce it by adding the following to your local settings.php:

assert_options(ASSERT_ACTIVE, TRUE);
\Drupal\Component\Assertion\Handle::register();

Attached a copy of a sample

views.view.list_of_users.yml

view config to replicate the issue.

  • Create a view which includes a field which incorporates token rewrites
  • Add the following query string to the view's URL: ?amp;page=0&amp;category[64]=64&page=0
  • Views will attempt to add invalid tokens such as: {{ arguments.amp;page }} into the list and subsequently fail its assertions

Proposed resolution

Validate that the query string parameters injected are actually valid twig variable tokens, skipping them otherwise.

Or alternatively detect those non-standard parameters, and replace with {{ arguments['amp;page'] }} type syntax.

Remaining tasks

Provide issue fork/patch.

User interface changes

N/A

API changes

N/A


Viewing all articles
Browse latest Browse all 300003

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>