Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case <?php in the PHP script itself #15

Open
anibalsanchez opened this issue Jan 17, 2019 · 2 comments
Open

Case <?php in the PHP script itself #15

anibalsanchez opened this issue Jan 17, 2019 · 2 comments

Comments

@anibalsanchez
Copy link
Contributor

anibalsanchez commented Jan 17, 2019

The plugin assumes that <?php is not present in the script itself. If <?php is included in the file, at any point, the engine injects the macro.yay in the result.

You can verify the issue in this file, processing it with any plugin: https://github.com/symfony/translation/blob/master/Translator.php#L344

As a workaround, I've implemented in the caller a preprocessing of the text to escape <?php before the call. But, I think it has to be fixed in the engine to support any PHP script.

@assertchris
Copy link
Member

I see what you're saying, but I can't get my head around a fix. Could you show me the code you've used to work around it, so I can get a better understanding of what needs to be done?

@anibalsanchez
Copy link
Contributor Author

The workaround is very simple. It just replaces the additionals <php with an encoded tag ºººhp. After the processing, it reverts the encoding:

// Escape <?php in the script text
$code = substr($code, 5);
$code = str_replace('<?php', 'ºººhp', $code);
$code = '<?php'.$code;

$parsedCode = Pre\Plugin\parse($code);

// Unescape <?php in the script text
$parsedCode = str_replace('ºººhp', '<?php', $parsedCode);

The alternative is changing how the macro is inserted in the dynamic code to avoid the <php as the signal to insert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants