cookies_filter adds <body> tag

Created on 11 August 2023, over 1 year ago
Updated 26 October 2023, about 1 year ago

Problem/Motivation

When using the cookies_filter to knock out YouTube videos from the site, pages that have YouTube videos on them are getting an additional <body> tag injected into the site nested further down the DOM tree around the content that was modified.

Steps to reproduce

  1. Create a Cookies Service Filter Entity
  2. Configure it to use the Videos provided by YouTube service
  3. Configure it to use the iframe Element Type
  4. Post a blog with an embedded YouTube iframe
  5. view-source on the published blog page and search for <body and find there are 2 matches

Proposed resolution

I suspect the problem stems from the filterTextByServiceFilter function in cookies_filter/Services/CookiesFilterElementTypesService.php. The Crawler object (which is from Symfony\Component\DomCrawler) is being passed in text which needs to be parsed into a DOM. DomCrawler is not setup for handling fragments. The parseHtml5 function in DomCrawler calls Masterminds\HTML5 parse() rather than parseFragment(). I believe this is the root cause of the added body tag.

As a workaround, I was able to change the return statement of filterTextByServiceFilter to:
return $crawler->children()->html();
but I believe this might fix only my use case, not all use cases of cookies_filter

πŸ› Bug report
Status

Postponed: needs info

Version

1.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States kevin_h

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024