Magento2: DOMDocument::loadHTML(): Tag date invalid in Entity

Created on 25 Nov 2019  路  13Comments  路  Source: magento/magento2

Preconditions (*)

  1. Magento 2.3.3 or 2.3-develop
  2. Simple Product is created.
  3. Customer is created and logged

Steps to reproduce (*)

  1. Add product to cart
  2. Place Order
  3. Click on the order number
    order
  4. The url is (/sales/order/view/order_id//)
  5. See exception.log

    Expected result (*)

No new exception log entries

Actual result (*)

New Exception Log Entry
DOM

Possible fix

in /module-sales/view/frontend/templates/order/order_date.phtml change "date" tag with "span"

Sales Fixed in 2.4.x Confirmed Format is valid Ready for Work Reproduced on 2.3.x

Most helpful comment

in /module-sales/view/frontend/templates/order/order_date.phtml change "date" tag with "span"

I can confirm this solves the exception error.

All 13 comments

Hi @nghelo. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

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

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

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

For more details, please, review the Magento Contributor Assistant documentation.

@nghelo do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

Hi @engcom-Echo. 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:

  • [ ] 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.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.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.

:white_check_mark: Confirmed by @engcom-Echo
Thank you for verifying the issue. Based on the provided information internal tickets MC-29223 were created

Issue Available: @engcom-Echo, _You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself._

Hi @AndreyChorniy. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [ ] 2. Verify that the issue is reproducible on 2.3-develop branch

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

  • [ ] 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


in /module-sales/view/frontend/templates/order/order_date.phtml change "date" tag with "span"

I can confirm this solves the exception error.

@GuiltyNL You mean like below. Replace "date" with "/span"

<div class="order-date">
    <?= $block->escapeHtml(__('<span class="label">Order Date:</span> %1', '</span>' . $block->formatDate($block->getOrder()->getCreatedAt(), \IntlDateFormatter::LONG) . '</date>'), ['span', 'date']) ?>
</div>

No like this:

<?php
/**
 * Copyright 漏 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
?>
<div class="order-date">
    <?= $block->escapeHtml(__('<span class="label">Order Date:</span> %1', '<span>' . $block->formatDate($block->getOrder()->getCreatedAt(), \IntlDateFormatter::LONG) . '</span>'), ['span', 'date']) ?>
</div>

I also receive this error when navigating to 'customer/account/'...the page mostly breaks and just displays a white background with the table of orders. Unfortunately changing order_date.phtml as suggested here did not solve my problem.

image

main.CRITICAL: DOMDocument::loadHTML(): Tag date invalid in Entity, line: 1 {"exception":"[object] (InvalidArgumentException(code: 2): DOMDocument::loadHTML(): Tag date invalid in Entity, line: 1 at ./public_html/vendor/magento/framework/Escaper.php:89)"} []

Update: I'm noticing this is only happening with old orders. I can view every order in the backend (as listed in my screenshot) except the oldest one; which blows up and shows a white screen when i attempt to view it. I'm thinking this is an upgrade issue; caused by the upgrade not gracefully upgrading the database to account for new code.

Update#2: I ultimately figured out my problem and corrected it. During one of the upgrades the product_options field in the sales_order_item table had corrupt data for 258 records. They were serialized wrong. I wrote a PHP program to scan through and correct the data.

Hi @nghelo. Thank you for your report.
The issue has been fixed in magento/magento2#25895 by @AndreyChorniy in 2.4-develop branch
Related commit(s):

The fix will be available with the upcoming 2.4.0 release.

EDIT: It turns out that PHP doesn't like the <time> element, even though the Escaper class does not explicitly forbid it, so the rest of this comment is aspirational.


I realize that you already made a relevant change about 5 weeks ago, but it would be more semantic if the <time> element were used.

Here's a variant that also depends on making datetime an allowed attribute in \Magento\Framework\Escaper:

<?php $orderDateTime = (new \DateTime($block->getOrder()->getCreatedAt())); ?>
<div class="order-date">
    <?= $block->escapeHtml(__('<span class="label">Order Date:</span> %1', '<time datetime="' . $orderDateTime->format('c') . '">' . $block->formatDate($orderDateTime, \IntlDateFormatter::LONG) . '</time>'), ['span', 'time']) ?>
</div>

Here's a variant that doesn't depend on making datetime allowed and is much simpler:

<div class="order-date">
    <?= $block->escapeHtml(__('<span class="label">Order Date:</span> %1', '<time>' . $block->formatDate($block->getOrder()->getCreatedAt(), \IntlDateFormatter::LONG) . '</time>'), ['span', 'time']) ?>
</div>

@lewisje I tried your solution and still receive the same exception. The original solution is still the answer.

That is quite surprising: It doesn't allow <time> either, even though that is a valid HTML5 element; it's not something banned in the Escaper class, so it must be a problem in PHP.

I upgraded from 2.3.3 to 2.3.4 and then from 2.3.4 to 2.3.5 and I still have the same error.
My shopping cart are international language.

Can anyone give me a tip?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andreaskoch picture andreaskoch  路  3Comments

denis-g picture denis-g  路  3Comments

MauroNigrele picture MauroNigrele  路  3Comments

ostmond picture ostmond  路  3Comments

xi-ao picture xi-ao  路  3Comments