You are here

function url_remove_dot_segments in Feeds Image Grabber 7

Filter out "." and ".." segments from a URL's path and return the result.

This function implements the "remove_dot_segments" algorithm from the RFC3986 specification for URLs.

This function supports multi-byte characters with the UTF-8 encoding, per the URL specification.

Parameters: path the path to filter

Return values: The filtered path with "." and ".." removed.

1 call to url_remove_dot_segments()
url_to_absolute in libraries/url_to_absolute.inc
Combine a base URL and a relative URL to produce a new absolute URL. The base URL is often the URL of a page, and the relative URL is a URL embedded on that page.

File

libraries/url_to_absolute.inc, line 107
Converts a relative URL to absolute URL.

Code

function url_remove_dot_segments($path) {

  // multi-byte character explode
  $inSegs = preg_split('!/!u', $path);
  $outSegs = array();
  foreach ($inSegs as $seg) {
    if ($seg == '' || $seg == '.') {
      continue;
    }
    if ($seg == '..') {
      array_pop($outSegs);
    }
    else {
      array_push($outSegs, $seg);
    }
  }
  $outPath = implode('/', $outSegs);
  if ($path[0] == '/') {
    $outPath = '/' . $outPath;
  }

  // compare last multi-byte character against '/'
  if ($outPath != '/' && mb_strlen($path) - 1 == mb_strrpos($path, '/', 'UTF-8')) {
    $outPath .= '/';
  }
  return $outPath;
}