The use of Heredoc syntax in the Magento 2 Friendly Captcha extension's .phtml files (introduced in version 3.x) is causing syntax errors when Magento's HTML minification setting is enabled. This issue affects environments where the Magento configuration under Stores -> Configuration -> Advanced -> Developer -> Template Settings -> Minify Html is set to Yes. When this setting is enabled, Magento minifies .phtml files, which leads to improperly processed Heredoc syntax causing ParseError: syntax error, unexpected token <<.
The .phtml template files should render without syntax errors, regardless of whether HTML minification is enabled or disabled in Magento's backend.
Actual Behavior
When HTML minification is enabled in production mode, the rendered .phtml files with Heredoc syntax cause a PHP parse error due to the compression of the file into a single line or other alterations that disrupt the proper end marking of the Heredoc block.
Steps to Reproduce
Configure and Enable extension at Stores -> Configuration -> Security -> Friendly Captcha
Set Magento to production mode.
Enable HTML minification at Stores -> Configuration -> Advanced -> Developer -> Template Settings -> Minify Html or execute ./bin/magento config:set dev/template/minify_html 1 command.
Clear cache.
Navigate to a page where the Friendly Captcha is supposed to load. For example to Login page.
Observe the system.log and page crash due to a syntax error.
Error from system.log
[2024-09-04T08:32:28.642497+00:00] main.CRITICAL: ParseError: syntax error, unexpected token "<<" in /Users/user/Sites/main/project/src/var/view_preprocessed/pub/static/vendor/imi/magento2-friendly-captcha/view/frontend/templates/imi_friendly_captcha.phtml:1
Minified content of var/view_preprocessed/pub/static/vendor/imi/magento2-friendly-captcha/view/frontend/templates/imi_friendly_captcha.phtml
Description
Overview
The use of Heredoc syntax in the Magento 2 Friendly Captcha extension's .phtml files (introduced in version 3.x) is causing syntax errors when Magento's HTML minification setting is enabled. This issue affects environments where the Magento configuration under
Stores -> Configuration -> Advanced -> Developer -> Template Settings -> Minify Html
is set to Yes. When this setting is enabled, Magento minifies .phtml files, which leads to improperly processed Heredoc syntax causingParseError: syntax error, unexpected token <<
.Affected Files
Expected Behavior
The .phtml template files should render without syntax errors, regardless of whether HTML minification is enabled or disabled in Magento's backend.
Actual Behavior
When HTML minification is enabled in production mode, the rendered .phtml files with Heredoc syntax cause a PHP parse error due to the compression of the file into a single line or other alterations that disrupt the proper end marking of the Heredoc block.
Steps to Reproduce
Stores -> Configuration -> Security -> Friendly Captcha
Stores -> Configuration -> Advanced -> Developer -> Template Settings -> Minify Html
or execute./bin/magento config:set dev/template/minify_html 1
command.Error from system.log
[2024-09-04T08:32:28.642497+00:00] main.CRITICAL: ParseError: syntax error, unexpected token "<<" in /Users/user/Sites/main/project/src/var/view_preprocessed/pub/static/vendor/imi/magento2-friendly-captcha/view/frontend/templates/imi_friendly_captcha.phtml:1
Minified content of var/view_preprocessed/pub/static/vendor/imi/magento2-friendly-captcha/view/frontend/templates/imi_friendly_captcha.phtml