From 5a3a0abaf2897b807a1d5cbcba8ffd1e4509de8b Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Thu, 5 Aug 2021 08:31:38 +0100 Subject: [PATCH] Issue #3222616 by phenaproxima, vsujeetkumar, labboy0276, hmendes, cilefen: YouTube PlayLists can't be added to Remote Video due to regex issue --- core/modules/media/src/OEmbed/Endpoint.php | 2 +- .../media/tests/src/Unit/EndpointTest.php | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 core/modules/media/tests/src/Unit/EndpointTest.php diff --git a/core/modules/media/src/OEmbed/Endpoint.php b/core/modules/media/src/OEmbed/Endpoint.php index 97f97e2815fc..7740acf8b747 100644 --- a/core/modules/media/src/OEmbed/Endpoint.php +++ b/core/modules/media/src/OEmbed/Endpoint.php @@ -151,7 +151,7 @@ public function supportsDiscovery() { public function matchUrl($url) { foreach ($this->getSchemes() as $scheme) { // Convert scheme into a valid regular expression. - $regexp = str_replace(['.', '*'], ['\.', '.*'], $scheme); + $regexp = str_replace(['.', '*', '?'], ['\.', '.*', '\?'], $scheme); if (preg_match("|^$regexp$|", $url)) { return TRUE; } diff --git a/core/modules/media/tests/src/Unit/EndpointTest.php b/core/modules/media/tests/src/Unit/EndpointTest.php new file mode 100644 index 000000000000..cc7b5cceeb58 --- /dev/null +++ b/core/modules/media/tests/src/Unit/EndpointTest.php @@ -0,0 +1,27 @@ +<?php + +namespace Drupal\Tests\media\Unit; + +use Drupal\media\OEmbed\Endpoint; +use Drupal\Tests\UnitTestCase; + +/** + * @coversDefaultClass \Drupal\media\OEmbed\Endpoint + * + * @group media + */ +class EndpointTest extends UnitTestCase { + + /** + * @covers ::matchUrl + */ + public function testMatchUrl(): void { + $endpoint = new Endpoint( + 'https://www.youtube.com/oembed', + $this->createMock('\Drupal\media\OEmbed\Provider'), + ['https://*.youtube.com/playlist?list=*'] + ); + $this->assertTrue($endpoint->matchUrl('https://www.youtube.com/playlist?list=aBc-EzAs123')); + } + +} -- GitLab