Problem/Motivation

As of now, HTML::escapeCdataElement uses probably old way of commenting cdata element. For example, for cdata inside script tag the output is

<!--//--><![CDATA[// ><!--

But this is preventing Google to read structured data.

Steps to reproduce

In body (CKEditor) field, add script tag with some content. Ensure "Prevent faulty and Chopped off HTML" filter is selected for the Text format.

Proposed resolution

Probably using new ways of commenting cdata

//<![CDATA[

Reference Link: https://en.wikipedia.org/wiki/CDATA#Use_of_CDATA_in_program_output

Comments

purushotam.rai created an issue. See original summary.

purushotam.rai’s picture

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
gordon’s picture

Status: Active » Reviewed & tested by the community

I have tested this and added this to a client.

Basically the problem is that the start and end comment is being wrapped in a HTML comment which is not applicable in a style or script element.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests
Related issues: +#721536: HTML corrector filter has problems with unescaped CDATA and incorrectly closed tags

This patch will break the filter tests and also are we absolutely sure this approach is correct?

This code is very old and has been used by filters for years. If I put

<p><script>
<!--//--><![CDATA[// ><!--
alert("test")
//--><!]]>
</script></p>
<p><style>
<!--/*--><![CDATA[/* ><!--*/
 /* Styling */ body {color:red}
/*--><!]]>*/
</style>Test</p>

into https://validator.w3.org/ it does not come back with errors about cdata - and if I put this into a .htm file and open it in a browser it opens as expected.

That said looking at the link the issue summary the changes do look correct. I wonder if anyone is relying on the current behaviour.

This code has been this way since #721536: HTML corrector filter has problems with unescaped CDATA and incorrectly closed tags

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

believe this could be a duplicate of https://www.drupal.org/project/drupal/issues/3259255 which is further along.

smustgrave’s picture

Status: Needs work » Closed (duplicate)
Related issues: +#3259255: Html::escapeCdataElement() not adding CDATA correctly

closing as a duplicate.

If you feel this is a different issue please reopen.