public function Url::normalizePath

Normalize the URL so that double slashes and relative paths are removed

Return value

Url

File

drupal/core/vendor/guzzle/http/Guzzle/Http/Url.php, line 286

Class

Url
Parses and generates URLs based on URL parts. In favor of performance, URL parts are not validated.

Namespace

Guzzle\Http

Code

public function normalizePath() {
  if ($this->path == '*') {
    return $this;
  }
  if ($this->path && $this->path != '/') {

    // Replace // and /./ with /
    $this->path = str_replace(array(
      '/./',
      '//',
    ), '/', $this->path);

    // Remove trailing relative paths if possible
    $segments = $this
      ->getPathSegments();
    $last = end($segments);
    $trailingSlash = false;
    if ($last === '') {
      array_pop($segments);
      $trailingSlash = true;
    }
    while ($last == '..' || $last == '.') {
      if ($last == '..') {
        array_pop($segments);
        $last = array_pop($segments);
      }
      if ($last == '.' || $last == '') {
        $last = array_pop($segments);
      }
    }
    $this->path = implode('/', $segments);
    if ($trailingSlash) {
      $this->path .= '/';
    }
  }

  // Must always start with a slash
  if (substr($this->path, 0, 1) != '/') {
    $this->path = '/' . $this->path;
  }
  return $this;
}