- Issue created by @donquixote
In entity_print_entity_view_alter() we see a call to trim($export_type, '_engine')
.
The goal is to remove a '_engine' suffix from a an export type name.
However, what happens instead is that any of the characters that occur in '_engine' are removed from the end of the export type name.
E.g. trim('tree_engine', '_engine') is 'tr'.
https://3v4l.org/dVnuK
For now this is not a problem because none of the known export types end with any of these characters.
You would have to define an export type plugin with an id that ends with "e", or another one of the characters in "_engine".
However, a much easier way to replicate the problem that _would_ occur is by changing the code in entity_print_entity_view_alter().
In the trim() call, simply add another character: '_enginef' instead of '_engine'.
$route_params = [
'entity_type' => $entity->getEntityTypeId(),
'entity_id' => $entity->id(),
'revision_id' => $entity->getRevisionId() ?? '',
'export_type' => trim($export_type, '_enginef'),
];
Now visit a node page that would normally have the pdf link.
The link is not shown, until we remove the 'f' from the trim parameter.
I see two options:
1. Replace the `trim()` call with something that actually removes a suffix. E.g. `basename()` would work, although it seems strange in this context. Otherwise str_ends_with() + substr().
2. Check if the `trim()` if actually needed, and possibly remove it.
I also see another bad usage of trim() in FilenameGenerator::generateFilename().
This would go into a follow-up issue.
Active
2.0
Code