Problem/Motivation
- Create a view of nodes, add an exposed filter on the author (uid)
- Add enough nodes that it will need to use the pager
- Autocomplete the user that created the nodes above, submit the filter form
- Try to go to the next page, or any pager link
- Assertion Error (fatal if configured to do so e.g. settings.local.php config)
AssertionError: Tokens need to be valid Twig variables. in Drupal\Component\Assertion\Handle::Drupal\Component\Assertion\{closure}() (line 377 of core/modules/views/src/Plugin/views/PluginBase.php).
Proposed resolution
Tokens created from exposed input, like the autocomplete element (as it creates the nested structure with [['target_id' => VALUE]]) will generate tokens like arguments.author.0.target_id
. In PluginBase::viewsTokenReplace() the tokens are validated with assertions. Most of the time this is fine, but when tokens contains dots, they are split and each piece is evaluated with the same assertion:
assert('preg_match(\'/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/\', $key) === 1', 'Tokens need to be valid Twig variables.');
So using the example token above, one of the parts would be '0' which would fail here. We should check is_numeric() || preg_match() but only in the case each $part is being checked.
Remaining tasks
Tests?
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#9 | 2718717-9.patch | 1.95 KB | damiankloip |
#3 | 2718717-3.patch | 1.95 KB | damiankloip |
#3 | 2718717-3-tests-only-FAIL.patch | 927 bytes | damiankloip |
#2 | 2718717.patch | 1.04 KB | damiankloip |
Comments
Comment #2
damiankloip CreditAttribution: damiankloip commentedComment #3
damiankloip CreditAttribution: damiankloip commentedAnd with a test. Test only patch is also the interdiff.
Comment #4
damiankloip CreditAttribution: damiankloip at Tag1 Consulting commentedComment #6
catchLooks sensible.
Comment #7
dawehnerLooks ideal for me
Comment #9
damiankloip CreditAttribution: damiankloip at Tag1 Consulting commentedReroll.
Comment #10
jibranRTBC as per #7
It might need another reroll after #2734663: Update deprecation message for old KernelTestBase in simpletest.
Comment #11
dawehnerMaybe git can actually figure that out.
Comment #14
catchCommitted/pushed to both 8.x branches, thanks!
Comment #15
catch