Skip to content

Escaping for XML is caught by DiscouragedFunctionSniff #496

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

Open
fooman opened this issue Apr 27, 2025 · 1 comment
Open

Escaping for XML is caught by DiscouragedFunctionSniff #496

fooman opened this issue Apr 27, 2025 · 1 comment
Labels
enhancement Improvements to existing rules

Comments

@fooman
Copy link

fooman commented Apr 27, 2025

Description

The following code htmlspecialchars($string, ENT_XML1, "UTF-8") triggers the warning

38 | WARNING | The use of function htmlspecialchars() is discouraged; use
    |         | \Magento\Framework\Escaper->escapeHtml() instead
    |         | (Magento2.Functions.DiscouragedFunction.DiscouragedWithAlternative)

Expected behavior

The suggested alternative is not an equivalent solution. A brief search over the Magento codebase also reveals there is no mention of ENT_XML1. Also \Magento\Framework\Escaper::$htmlSpecialCharsFlag is a private property making it impossible to set ENT_XML1 in a custom implementation.

Benefits

Ensure XML content can be generated correctly with-in a Magento module.

Additional information

Solutions would be either to a.) ensure the discouraged function sniff only triggers in code that is covered by the alternative or b.) add options to escape for XML in \Magento\Framework\Escaper

@fooman fooman added the enhancement Improvements to existing rules label Apr 27, 2025
Copy link

m2-assistant bot commented Apr 27, 2025

Hi @fooman. Thank you for your report.
To speed up processing of this issue, make sure that you provided sufficient information.
Add a comment to assign the issue: @magento I am working on this


Join Magento Community Engineering Slack and ask your questions in #github channel.

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

No branches or pull requests

1 participant