Skip to content

Commit

Permalink
Incorrect routing caused by str_replace() in Uri::init() [#2754]
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Dec 10, 2019
1 parent 95bd217 commit 842dc0d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v1.6.20
## 12/04/2019

1. [](#bugfix)
* Incorrect routing caused by `str_replace()` in `Uri::init()` [#2754](https://github.com/getgrav/grav/issues/2754)

# v1.6.19
## 12/04/2019

Expand Down
18 changes: 9 additions & 9 deletions system/src/Grav/Common/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function init()

$this->url = $this->base . $this->uri;

$uri = str_replace(static::filterPath($this->root), '', $this->url);
$uri = Utils::replaceFirstOccurrence(static::filterPath($this->root), '', $this->url);

// remove the setup.php based base if set:
$setup_base = $grav['pages']->base();
Expand Down Expand Up @@ -195,7 +195,7 @@ public function init()
// set the new url
$this->url = $this->root . $path;
$this->path = static::cleanPath($path);
$this->content_path = trim(str_replace($this->base, '', $this->path), '/');
$this->content_path = trim(Utils::replaceFirstOccurrence($this->base, '', $this->path), '/');
if ($this->content_path !== '') {
$this->paths = explode('/', $this->content_path);
}
Expand Down Expand Up @@ -340,7 +340,7 @@ public function url($include_host = false)
return $this->url;
}

$url = str_replace($this->base, '', rtrim($this->url, '/'));
$url = Utils::replaceFirstOccurrence($this->base, '', rtrim($this->url, '/'));

return $url ?: '/';
}
Expand Down Expand Up @@ -489,7 +489,7 @@ public function uri($include_root = true)
return $this->uri;
}

return str_replace($this->root_path, '', $this->uri);
return Utils::replaceFirstOccurrence($this->root_path, '', $this->uri);
}

/**
Expand Down Expand Up @@ -531,7 +531,7 @@ public function rootUrl($include_host = false)
return $this->root;
}

return str_replace($this->base, '', $this->root);
return Utils::replaceFirstOccurrence($this->base, '', $this->root);
}

/**
Expand Down Expand Up @@ -783,7 +783,7 @@ public static function convertUrl(PageInterface $page, $url, $type = 'link', $ab
}

// special check to see if path checking is required.
$just_path = str_replace($normalized_url, '', $normalized_path);
$just_path = Utils::replaceFirstOccurrence($normalized_url, '', $normalized_path);
if ($normalized_url === '/' || $just_path === $page->path()) {
$url_path = $normalized_url;
} else {
Expand Down Expand Up @@ -852,7 +852,7 @@ public static function convertUrl(PageInterface $page, $url, $type = 'link', $ab
}

// strip base from this path
$target_path = str_replace($uri->rootUrl(), '', $target_path);
$target_path = Utils::replaceFirstOccurrence($uri->rootUrl(), '', $target_path);

// set to / if root
if (empty($target_path)) {
Expand All @@ -877,7 +877,7 @@ public static function convertUrl(PageInterface $page, $url, $type = 'link', $ab

// Handle route only
if ($route_only) {
$url_path = str_replace(static::filterPath($base_url), '', $url_path);
$url_path = Utils::replaceFirstOccurrence(static::filterPath($base_url), '', $url_path);
}

// transform back to string/array as needed
Expand Down Expand Up @@ -998,7 +998,7 @@ public static function convertUrlOld(PageInterface $page, $markdown_url, $type =
}

// special check to see if path checking is required.
$just_path = str_replace($normalized_url, '', $normalized_path);
$just_path = Utils::replaceFirstOccurrence($normalized_url, '', $normalized_path);
if ($just_path === $page->path()) {
return $normalized_url;
}
Expand Down

0 comments on commit 842dc0d

Please sign in to comment.