Skip to content

Escaping for XML is caught by DiscouragedFunctionSniff #496

Open
@fooman

Description

@fooman

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovements to existing rules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy