Oembed broken for multi-language sites

Created on 19 November 2024, about 1 month ago

Problem/Motivation

Klaro! handles the requests to /media/oembed in special way. On multi-language sites these requests are language prefixed and will not be handled this way and the blocking is broken.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇩🇪Germany jan kellermann

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @jan kellermann
  • Merge request !37oEmbed: Check for language prefix also. → (Merged) created by jan kellermann
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Hmm, that MR seems to make an assumption, that there is a path prefix with the langcode. I think, that's not always the case. And there are probably even more ways to alter the routing.

    Isn't it possible to use the Url service from Drupal to receive the correct path?

  • 🇩🇪Germany jan kellermann

    I used with and without prefix. But you are right: checking the route is the better solution. Commit added.

  • depending on how content/interface language detection is configured and whether content is translated in the detected language
    the check by langcode might be unsuccessful.
    checking if the initial_path ends with '/media/oembed' seems more reliable:

    diff --git a/src/Utility/KlaroHelper.php b/src/Utility/KlaroHelper.php
    index ef408e3..14e4f03 100644
    --- a/src/Utility/KlaroHelper.php
    +++ b/src/Utility/KlaroHelper.php
    @@ -811,8 +811,6 @@ class KlaroHelper {
           }
         }
     
    -    $langcode = $this->languageManager->getCurrentLanguage()->getId();
    -
         foreach ($dom->getElementsByTagName('iframe') as $iframe) {
           if ($iframe->hasAttribute('data-src') && $iframe->hasAttribute('data-name')) {
             continue;
    @@ -821,7 +819,7 @@ class KlaroHelper {
           $initial_path = parse_url($initial_src, PHP_URL_PATH);
     
           // If remote-video matchKlaroApp against url parameter.
    -      if ((strpos($initial_path, '/media/oembed') === 0) || (strpos($initial_path, '/' . $langcode . '/media/oembed') === 0)) {
    +      if (str_ends_with($initial_path, '/media/oembed')) {
             parse_str(parse_url($initial_src, PHP_URL_QUERY), $params);
             $found_klaro_app = $this->matchKlaroApp($params['url']);
           }
    
  • 🇩🇪Germany jan kellermann

    Thank you, @van.dordafog
    I changed the code and updated the MR.

  • 🇩🇪Germany jan kellermann

    Thank you all for testing and feedback. I merge this and will tag a new RC.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024