Problem/Motivation

OEmbed\Endpoint::buildResourceUrl() incorrectly appends a second question mark if the provider endpoint already contains a query string.

A similar bug exists in UpdateFetcher::buildFetchUrl(), which appends the project-specific URL suffix and optional usage information after an existing fragment, preventing them from being transmitted to the update server.

Steps to reproduce

The oEmbed provider hearthis.at uses an endpoint that already contains a query parameter:
https://hearthis.at/oembed/?format=json

  1. Enable the Media module.
  2. Add hearthis.at to the providers array in OEmbedDeriver::getDerivativeDefinitions(), clear caches and make sure the provider is allowed in the Remote video media type settings.
  3. Add a Remote video media item using https://hearthis.at/dj-molotov/siamo-tutti-antifa-set-mix/ as the source URL.
  4. Save the media item.

The generated request URL contains ?format=json?url= instead of ?format=json&url=.

When adding a new media item in the UI, Drupal therefore reports:

The provided URL does not represent a valid oEmbed resource.

When created programmatically, bypassing validation, a 400 Bad Request response is displayed instead of the embedded media player:

before

The loosely related UpdateFetcher bug can be reproduced programmatically by providing a base URL containing a fragment.

Proposed resolution

  • Introduce UrlHelper::appendQueryString() to centralize query string assembly, which is currently handled inconsistently, to ensure existing query strings and fragments are handled correctly across Core.
  • Use it in both affected methods.
  • Ensure the project-specific URL suffix in UpdateFetcher::buildFetchUrl() is also appended before the fragment.

Remaining tasks

Review.

User interface changes

Previously failing oEmbed resources can now be added and displayed correctly:

after

Introduced terminology

None.

API changes

Added UrlHelper::appendQueryString().

Data model changes

None.

Release notes snippet

Fixed oEmbed resource fetching for provider endpoints containing existing query parameters and corrected fragment handling in update URLs by introducing a common helper to ensure consistency.

CommentFileSizeAuthor
oEmbed_after.png45.47 KBpancho
oEmbed_before.png30.5 KBpancho

Issue fork drupal-3641566

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pancho created an issue. See original summary.

pancho’s picture

Status: Active » Needs review