InvalidArgumentException when path segment starts with colon

Created on 16 January 2023, almost 2 years ago
Updated 29 November 2023, 12 months ago

Problem/Motivation

If a path segment starts with a colon, you get an error:

InvalidArgumentException: The URI ':foo' is invalid. You must use a valid URI scheme. in Drupal\Core\Url::fromUri() (line 293 of core/lib/Drupal/Core/Url.php).

Drupal\Core\Path\PathValidator->getUrl(':foo', ) (Line: 89)
Drupal\Core\Path\PathValidator->getUrlIfValidWithoutAccessCheck('/:foo') (Line: 183)
Drupal\menu_trail_by_path\MenuTrailByPathActiveTrail->getCurrentRequestUrl() (Line: 161)
Drupal\menu_trail_by_path\MenuTrailByPathActiveTrail->getTrailUrls() (Line: 137)
Drupal\menu_trail_by_path\MenuTrailByPathActiveTrail->getActiveTrailLink('meta') (Line: 118)
Drupal\menu_trail_by_path\MenuTrailByPathActiveTrail->doGetActiveTrailIds('meta') (Line: 71)

We have quite a lot of these log entries with some random URLs in the path segment (like "https://my.site/:http://www.example.com/wiki/index.php").

Steps to reproduce

Try to access https://my.site/:foo or https://my.site/:foo/bar.

Proposed resolution

While checking the path, take invalid ones into account (according to RFC 3986).

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇩🇪Germany pminf Nuremburg (Germany), formerly Dresden

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

Merge Requests

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