Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. UriResolver.php

function UriResolver::removeDotSegments

Removes dot segments from a path and returns the new path.

See also

https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.4

2 calls to UriResolver::removeDotSegments()
UriNormalizer::normalize in vendor/guzzlehttp/psr7/src/UriNormalizer.php
Returns a normalized URI.
UriResolver::resolve in vendor/guzzlehttp/psr7/src/UriResolver.php
Converts the relative URI into a new URI that is resolved against the base URI.

File

vendor/guzzlehttp/psr7/src/UriResolver.php, line 23

Class

UriResolver
Resolves a URI reference in the context of a base URI and the opposite way.

Namespace

GuzzleHttp\Psr7

Code

public static function removeDotSegments(string $path) : string {
    if ($path === '' || $path === '/') {
        return $path;
    }
    $results = [];
    $segments = explode('/', $path);
    foreach ($segments as $segment) {
        if ($segment === '..') {
            array_pop($results);
        }
        elseif ($segment !== '.') {
            $results[] = $segment;
        }
    }
    $newPath = implode('/', $results);
    if ($path[0] === '/' && (!isset($newPath[0]) || $newPath[0] !== '/')) {
        // Re-add the leading slash if necessary for cases like "/.."
        $newPath = '/' . $newPath;
    }
    elseif ($newPath !== '' && ($segment === '.' || $segment === '..')) {
        // Add the trailing slash if necessary
        // If newPath is not empty, then $segment must be set and is the last segment from the foreach
        $newPath .= '/';
    }
    return $newPath;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal