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

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

Closed
4 tasks
mrlerch opened this issue Oct 23, 2021 · 10 comments
Assignees
Labels
Component: Bundled Extension Issue is caused by one of the bundled extensions Issue: ready for confirmation Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.4.3-p1 Indicates original Magento version for the Issue report. Severity: S1 Affects critical data or functionality and forces users to employ a workaround.

Comments

@mrlerch
Copy link

mrlerch commented Oct 23, 2021

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 (*)

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.

  • [x ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

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
Copy link

m2-assistant bot commented Oct 23, 2021

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

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

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.


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 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.

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

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

@hostep
Copy link
Contributor

hostep commented Oct 23, 2021

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 #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
Copy link

simonmaass commented Oct 24, 2021

@hostep this error come from same problem because declare(strict_types=1) was added: #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
Copy link
Author

mrlerch commented Oct 24, 2021 via email

@ihor-sviziev ihor-sviziev added the Severity: S1 Affects critical data or functionality and forces users to employ a workaround. label Oct 25, 2021
@ihor-sviziev
Copy link
Contributor

@sidolov, please set priority to P1

@ihor-sviziev ihor-sviziev added the Reported on 2.4.3-p1 Indicates original Magento version for the Issue report. label Oct 25, 2021
@sidolov sidolov added the Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. label Oct 25, 2021
@m2-community-project m2-community-project bot added this to Ready for Development in High Priority Backlog Oct 25, 2021
@m2-community-project m2-community-project bot removed this from Ready for Confirmation in Issue Confirmation and Triage Board Oct 25, 2021
@m2-assistant
Copy link

m2-assistant bot commented Jun 7, 2022

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: 👇

    1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
      DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
    1. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.
    1. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
    1. Verify that the issue is reproducible on 2.4-develop branch
      Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
      - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
      - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

@m2-community-project m2-community-project bot moved this from Ready for Development to Dev In Progress in High Priority Backlog Jun 7, 2022
@SergeyP18
Copy link

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

@SergeyP18
Copy link

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

@engcom-November engcom-November self-assigned this Sep 1, 2022
@m2-assistant
Copy link

m2-assistant bot commented Sep 1, 2022

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: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-November
Copy link
Contributor

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.

@m2-community-project m2-community-project bot moved this from Dev In Progress to Done in High Priority Backlog Sep 1, 2022
@engcom-November engcom-November added Component: Bundled Extension Issue is caused by one of the bundled extensions and removed Progress: done labels Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Bundled Extension Issue is caused by one of the bundled extensions Issue: ready for confirmation Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.4.3-p1 Indicates original Magento version for the Issue report. Severity: S1 Affects critical data or functionality and forces users to employ a workaround.
Projects
Development

No branches or pull requests

7 participants