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

PHP8.2 compatibility #775

Merged
merged 8 commits into from
Nov 22, 2022
Merged

PHP8.2 compatibility #775

merged 8 commits into from
Nov 22, 2022

Conversation

Progi1984
Copy link
Contributor

Added suport for PHP8.2 compatibility.

Thanks @ophian

@Progi1984 Progi1984 marked this pull request as ready for review July 25, 2022 11:58
@ophian
Copy link

ophian commented Jul 25, 2022

@Progi1984
Please check modifier escape diff. I think mine at #767 looks different, see flags and additional parenthesis.
Did you run tests on this?

@Progi1984
Copy link
Contributor Author

@ophian I fixed it and rebase the PR.

@ophian ophian mentioned this pull request Aug 10, 2022
@wisskid
Copy link
Contributor

wisskid commented Aug 19, 2022

Please have a look at the unit tests? There are still failures.

@Progi1984
Copy link
Contributor Author

@wisskid I just fixed tests. Thanks
image

@Progi1984
Copy link
Contributor Author

Hi @wisskid, have you some time to restart the CI, please ?

@wisskid
Copy link
Contributor

wisskid commented Sep 14, 2022

CI is running. Can you explain the changes to the escape modifier compiler? It seems different in the way the methods are nested.

@Progi1984
Copy link
Contributor Author

@wisskid The CI is fixed.

I checked PHPUnit on PHP 8.2 RC / PHP 8.1 / PHP 8.0 / PHP 7.4 / PHP 7.3 / PHP 7.2 : https://github.com/Progi1984/smarty/actions/runs/3060762059

The encoding HTML-ENTITIES has been deprecated since PHP 8.2 : https://php.watch/versions/8.2/mbstring-qprint-base64-uuencode-html-entities-deprecated#html and tried to use the suggested replacement by php.watch. In this way, unit tests are not broken (Thanks to them 🙏)

@ophian
Copy link

ophian commented Sep 16, 2022

Hi @Progi1984 Could you elaborate why this change was necessary? Was there an error you had?
libs/sysplugins/smarty_internal_runtime_make_nocache.php

BTW.
You were right adding the additional htmlspecialchars( to the escape modifier. I discovered that later also when I made some extending tests with escape etc. (I have some more on this to include) But I still think the ENT_COMPAT set should follow the PHP 8.2 change of giving it up in favour of the ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML40 triplet.

@Progi1984
Copy link
Contributor Author

@ophian Of course, in PHP 8.2, Smarty_Variable becomes \Smarty_Variable in var_export of the variable. So the regex didn't work.

I check the change (ENT_COMPAT => ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401) in all versions and it's OK.

CI is 🟢 : https://github.com/Progi1984/smarty/actions/runs/3080652601

@Progi1984
Copy link
Contributor Author

Hi @wisskid, have you some time to restart the CI, please ?

@Progi1984
Copy link
Contributor Author

Thanks for the CI @wisskid : it's 🟢

@Progi1984
Copy link
Contributor Author

Hi @wisskid, have you some time to review this PR, please ? Thanks for your time.

@wisskid
Copy link
Contributor

wisskid commented Oct 17, 2022

@Progi1984 this looks great! I'll double check the encoding/escaping change and merge asap.

} else {
// fall back to modifier.escape.php
}
return 'htmlspecialchars_decode(mb_convert_encoding(htmlentities(htmlspecialchars((string)' . $params[ 0 ] . ', ENT_QUOTES, ' .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Progi1984 I still fail to see what is happening here. The unit tests are passing, but this nesting doesn't feel right. The php.watch site says "Although not recommended, if the '"<>& must not be encoded, this behavior can be achieved with an htmlspecialchars_decode call". This doesn't apply here. Should we just use htmlentities like on line 52?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@ophian
Copy link

ophian commented Oct 18, 2022

@wisskid I would recommend to merge my PR #781 first, since that is the Smarty 4.2.0/1 cleanup as a base for the PHP 8.2 fixes.

@Progi1984
Copy link
Contributor Author

@wisskid I checked PHPUnit with : PHP 8.2 RC5 ✔️ / PHP 8.1 ✔️ / PHP 8.0 ✔️ / PHP 7.4 ✔️ / PHP 7.3 ✔️ / PHP 7.2 ✔️

Sorry : I have removed your changes (but I have re-implemented in 4c39c54). And the PR has been rebased.

libs/plugins/modifier.escape.php Outdated Show resolved Hide resolved
} else {
// fall back to modifier.escape.php
}
return 'htmlspecialchars_decode(mb_convert_encoding(htmlentities(htmlspecialchars((string)' . $params[ 0 ] . ', ENT_QUOTES, ' .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@wisskid wisskid merged commit c016895 into smarty-php:master Nov 22, 2022
@Progi1984 Progi1984 deleted the php82 branch November 22, 2022 20:44
@Progi1984
Copy link
Contributor Author

Progi1984 commented Nov 22, 2022

🎉 @wisskid (and thanks for discussions)

peterpeppered pushed a commit to peterpeppered/smarty that referenced this pull request Oct 26, 2023
* PHP8.2 compatibility

* PHP8.2 compatibility : Fixed unit tests

* PHP8.2 compatibility : Replace ENT_COMPAT by ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401

* PHP8.2 compatibility : Remove deprecated utf8_decode

* PHP8.2 compatibility : Remove HTML-ENTITIES parameter

* Removed some unused code for clarity, updated the changelog.

* More concise escape implementation and unit test to cover both modifierplugin and modifiercompiler.

* Fix htmlall unescape of quotes without mbstring too

Co-authored-by: Simon Wisselink <s.wisselink@iwink.nl>
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

Successfully merging this pull request may close these issues.

3 participants