magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.48k stars 9.29k forks source link

M 2.4.3-p1 - TypeError: htmlspecialchars() expects parameter 1 to be string, null given in vendor/magento/framework/Escaper.php:417 #34413

Closed mrlerch closed 2 years ago

mrlerch commented 2 years ago

Preconditions (*)

  1. Magento 2.4.3-p1
  2. Debian GNU/Linux 9.13 (stretch) PHP 7.4.24, 5.7.34 MySQL Community Server Server version: Apache/2.4.25 (Debian) Server built: 2021-10-02T13:27:55

Steps to reproduce (*)

  1. Magento Store Frontend: add an item to the cart
  2. Log in to a Magento customer account profile
  3. Go to Shopping Cart page as logged in customer

Expected result (*)

  1. I would see logged in user shopping cart with item in it

Actual result (*)

  1. TypeError: htmlspecialchars() expects parameter 1 to be string, null given in /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/Escaper.php:417
    Stack trace:
    #0 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/Escaper.php(417): htmlspecialchars()
    #1 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/woopra/analytics-m2/Block/Script.php(127): Magento\Framework\Escaper->escapeQuote()
    #2 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/woopra/analytics-m2/view/frontend/templates/script.phtml(13): Woopra\Analytics\Block\Script->getSetting()
    #3 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/TemplateEngine/Php.php(71): include('/var/www/html/d...')
    #4 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/Element/Template.php(273): Magento\Framework\View\TemplateEngine\Php->render()
    #5 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/Element/Template.php(303): Magento\Framework\View\Element\Template->fetchView()
    #6 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/Element/AbstractBlock.php(1114): Magento\Framework\View\Element\Template->_toHtml()
    #7 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/Element/AbstractBlock.php(1118): Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}()
    #8 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/Element/AbstractBlock.php(678): Magento\Framework\View\Element\AbstractBlock->_loadCache()
    #9 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/Layout.php(578): Magento\Framework\View\Element\AbstractBlock->toHtml()
    #10 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/Layout.php(555): Magento\Framework\View\Layout->_renderBlock()
    #11 /var/www/html/domains/dev.proproductssales.com/public_html/generated/code/Magento/Framework/View/Layout/Interceptor.php(149): Magento\Framework\View\Layout->renderNonCachedElement()
    #12 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/Layout.php(510): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement()
    #13 /var/www/html/domains/dev.proproductssales.com/public_html/generated/code/Magento/Framework/View/Layout/Interceptor.php(140): Magento\Framework\View\Layout->renderElement()
    #14 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/Element/AbstractBlock.php(529): Magento\Framework\View\Layout\Interceptor->renderElement()
    #15 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/module-theme/view/frontend/templates/html/container.phtml(7): Magento\Framework\View\Element\AbstractBlock->getChildHtml()
    #16 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/TemplateEngine/Php.php(71): include('/var/www/html/d...')
    #17 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/Element/Template.php(273): Magento\Framework\View\TemplateEngine\Php->render()
    #18 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/Element/Template.php(303): Magento\Framework\View\Element\Template->fetchView()
    #19 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/Element/AbstractBlock.php(1114): Magento\Framework\View\Element\Template->_toHtml()
    #20 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/Element/AbstractBlock.php(1118): Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}()
    #21 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/Element/AbstractBlock.php(678): Magento\Framework\View\Element\AbstractBlock->_loadCache()
    #22 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/Result/Page.php(253): Magento\Framework\View\Element\AbstractBlock->toHtml()
    #23 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/View/Result/Layout.php(171): Magento\Framework\View\Result\Page->render()
    #24 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Result\Layout->renderResult()
    #25 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Result\Page\Interceptor->___callParent()
    #26 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}()
    #27 /var/www/html/domains/dev.proproductssales.com/public_html/generated/code/Magento/Framework/View/Result/Page/Interceptor.php(95): Magento\Framework\View\Result\Page\Interceptor->___callPlugins()
    #28 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/App/Http.php(120): Magento\Framework\View\Result\Page\Interceptor->renderResult()
    #29 /var/www/html/domains/dev.proproductssales.com/public_html/generated/code/Magento/Framework/App/Http/Interceptor.php(23): Magento\Framework\App\Http->launch()
    #30 /var/www/html/domains/dev.proproductssales.com/public_html/vendor/magento/framework/App/Bootstrap.php(264): Magento\Framework\App\Http\Interceptor->launch()
    #31 /var/www/html/domains/dev.proproductssales.com/public_html/pub/index.php(29): Magento\Framework\App\Bootstrap->run()
    #32 {main}

Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

Looked at the function including line 417 in Escaper.php

public function escapeQuote($data, $addSlashes = false)
    {
        if ($addSlashes === true) {
            $data = addslashes($data);
        }

        return htmlspecialchars($data, $this->htmlSpecialCharsFlag, null, false);

    }

Temporary fix: Created a module that overrides this function with this one:

public function escapeQuote($data, $addSlashes = false)
    {
        if ($addSlashes === true) {
            $data = addslashes($data);
        }
        if (!empty($data)) {
            return htmlspecialchars($data, $this->htmlSpecialCharsFlag, null, false);
        } else { 
            return $data; 
        } 
    }

Now it is working but I think that this is a bug possibly (why would there be an error if data is empty?)

m2-assistant[bot] commented 2 years ago

Hi @mrlerch. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

hostep commented 2 years ago

Thanks for reporting this @mrlerch

For the engcom squad reviewers: note that there is a 3rd party module woopra/analytics-m2 in the stacktrace that probably is the cause of this issue and it might not immediately be reproducible in a vanilla Magento installation. But that doesn't mean this bug isn't real.

This bug might possibly have been introduced by https://github.com/magento/magento2/pull/32002 where declare(strict_types=1); got added to the Escaper class. We should be more careful when adding that declaration to existing files and make sure that all calls in that class are forced to use the correct types.

@ihor-sviziev: does that make sense? Maybe collaborate with the other maintainers about this a bit if you can 🙂

The suggested change is not 100% correct as it would still allow addslashes to fail with the same problem when $addSlashes is set to true

simonmaass commented 2 years ago

@hostep this error come from same problem because declare(strict_types=1) was added: https://github.com/magento/magento2/issues/34415... its about a totally different file but just wanted to add to your comment about "We should be more careful when adding that declaration to existing files"

mrlerch commented 2 years ago

Here is my post on github.

Now what…

https://github.com/magento/magento2/issues/34413

Martin Lerch 702.321.0908 (mobile)

Sent from my iPhone (mobile)


The information contained in this communication is potentially confidential, and intended only for the use of the addressee. If you received this communication in error, please notify us by return e-mail and delete this communication and all copies, including all attachments.


On Oct 24, 2021, at 11:22 AM, Simon Maass @.***> wrote:

 @hostep this error come from same problem because declare(strict_types=1) was added: #34415

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

ihor-sviziev commented 2 years ago

@sidolov, please set priority to P1

m2-assistant[bot] commented 2 years ago

Hi @SergeyP18. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:


SergeyP18 commented 2 years ago

Error in a third-party module, check for the type of the transferred value does not pass

SergeyP18 commented 2 years ago

There is no check for value type. There is only a check if there is a value Снимок экрана от 2022-06-08 21-54-25

m2-assistant[bot] commented 2 years ago

Hi @engcom-November. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-November commented 2 years ago

Hi @mrlerch , Thank you for reporting and collaboration. However, Woopra is a 3rd party extension and code of this extension is not part of https://github.com/magento/magento2 git repository. We are closing this issue as community is not able to provide fix for it in this repository. All questions, issue reports and fix for them should be addressed to the corresponding extension owners(support) on the Magento Market place page Thank you.