function file_uri_normalize_dot_segments

Normalize dot segments in a URI.

Parameters

$uri: A stream, referenced as "scheme://target".

Return value

string The URI with dot segments removed and slashes as directory separator.

Related topics

3 calls to file_uri_normalize_dot_segments()
file_download in includes/file.inc
Menu handler for private file transfers.
image_style_deliver in modules/image/image.module
Page callback: Generates a derivative, given a style and image path.
image_style_url in modules/image/image.module
Returns the URL for an image derivative given a style and image path.

File

includes/file.inc, line 2751

Code

function file_uri_normalize_dot_segments($uri) {
  $scheme = file_uri_scheme($uri);
  if (file_stream_wrapper_valid_scheme($scheme)) {
    $target = file_uri_target($uri);
    if ($target !== FALSE) {
      if (!in_array($scheme, variable_get('file_sa_core_2023_005_schemes', array()))) {
        $class = file_stream_wrapper_get_class($scheme);
        $is_local = is_subclass_of($class, 'DrupalLocalStreamWrapper');
        if ($is_local) {
          $target = str_replace(DIRECTORY_SEPARATOR, '/', $target);
        }
        $parts = explode('/', $target);
        $normalized_parts = array();
        while ($parts) {
          $part = array_shift($parts);
          if ($part === '' || $part === '.') {
            continue;
          }
          elseif ($part === '..' && $is_local && $normalized_parts === array()) {
            $normalized_parts[] = $part;
            break;

          }
          elseif ($part === '..') {
            array_pop($normalized_parts);
          }
          else {
            $normalized_parts[] = $part;
          }
        }
        $target = implode('/', array_merge($normalized_parts, $parts));
      }
      $uri = $scheme . '://' . $target;
    }
  }
  return $uri;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.