Problem/Motivation
Localize.Drupal.org went into an infinite loop due to parsing this PHP code:
$form['description'] = [
'#type' => 'item',
'#markup' => $this->t('Add links to be displayed in the footer of emails sent by Symfony Mailer. These links will be available in all languages.<br>Example of usage in the template:<br><pre>@code</pre>', [
'@code' => <<<TWIG
{% if footer_links is not empty %}
<tr>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
{% for link in footer_links %}
<td>{{ link }}</td>
{% endfor %}
</tr>
</table>
</tr>
{% endif %}
TWIG,
]),
];
While this looks fine, the problem is at TWIG, which is "flexible heredoc syntax" shipped in PHP 7.3: https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes
Previously the heredoc would only be tokenized as heredoc-end if there was a newline, now the comma can be there. Older PHP does not understand the PHP 7.3+ flexible HEREDOC syntax (indented closing markers and tokens on the same line after the heredoc end). Instead of properly tokenizing them, it treats the entire content including the closing marker AND everything that follows as T_ENCAPSED_AND_WHITESPACE, including all subsequent PHP code!
This was triggered by https://www.drupal.org/project/symfony_mailer_addons/releases/1.0.0-beta1.
Proposed resolution
Add graceful fail for this case and test coverage.
Remaining tasks
User interface changes
API changes
Data model changes
LLM disclosure
LLM was used to analyze the problem, excperiment with solutions and write the tests. Everything was manually reviewed.
Issue fork potx-3563293
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
drummThis looks like the same code change will apply to 8.x-1.x
Comment #4
drummWith the patch applied, the logs still have
Which suggests
_potx_skip_args()is called with an out-of-bounds$hereto begin with. So either the calling code and/or bounds checking at the start of the function could likely be improved.I don’t have that deep of knowledge of the code here, so someone else should pick this up. The patch deployed so far is sufficient to unblock the production cron.
Comment #6
gábor hojtsyAccidentally committed the modern port to https://git.drupalcode.org/project/potx/-/commit/c3577a472a8dad2e0b0acaa... directly, that also passed there btw. I will merge the 7.x fix here.
Comment #7
gábor hojtsyUpdated issue summary heavily.
Comment #8
gábor hojtsyComment #10
gábor hojtsyComment #12
gábor hojtsy