Merge branch 'develop' of github.com:getgrav/grav into 1.7

 Conflicts:
	CHANGELOG.md
This commit is contained in:
Matias Griese
2019-12-10 19:09:02 +02:00
4 changed files with 61 additions and 32 deletions

View File

@@ -206,6 +206,14 @@
* Optimization: Initialize debugbar only after the configuration has been loaded
* Optimization: Combine some early Grav processors into a single one
# v1.6.20
## mm/dd/2019
1. [](#bugfix)
* Fixed incorrect routing caused by `str_replace()` in `Uri::init()` [#2754](https://github.com/getgrav/grav/issues/2754)
* Fixed session cookie is being set twice in the HTTP header [#2745](https://github.com/getgrav/grav/issues/2745)
* Fixed filesystem iterator calls with non-existing folders
# v1.6.19
## 12/04/2019

View File

@@ -22,6 +22,10 @@ abstract class Folder
*/
public static function lastModifiedFolder($path)
{
if (!file_exists($path)) {
return 0;
}
$last_modified = 0;
/** @var UniformResourceLocator $locator */
@@ -55,6 +59,10 @@ abstract class Folder
*/
public static function lastModifiedFile($path, $extensions = 'md|yaml')
{
if (!file_exists($path)) {
return 0;
}
$last_modified = 0;
/** @var UniformResourceLocator $locator */
@@ -91,21 +99,24 @@ abstract class Folder
*/
public static function hashAllFiles($path)
{
$flags = \RecursiveDirectoryIterator::SKIP_DOTS;
$files = [];
/** @var UniformResourceLocator $locator */
$locator = Grav::instance()['locator'];
if ($locator->isStream($path)) {
$directory = $locator->getRecursiveIterator($path, $flags);
} else {
$directory = new \RecursiveDirectoryIterator($path, $flags);
}
if (file_exists($path)) {
$flags = \RecursiveDirectoryIterator::SKIP_DOTS;
$iterator = new \RecursiveIteratorIterator($directory, \RecursiveIteratorIterator::SELF_FIRST);
/** @var UniformResourceLocator $locator */
$locator = Grav::instance()['locator'];
if ($locator->isStream($path)) {
$directory = $locator->getRecursiveIterator($path, $flags);
} else {
$directory = new \RecursiveDirectoryIterator($path, $flags);
}
foreach ($iterator as $file) {
$files[] = $file->getPathname() . '?'. $file->getMTime();
$iterator = new \RecursiveIteratorIterator($directory, \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $file) {
$files[] = $file->getPathname() . '?'. $file->getMTime();
}
}
return md5(serialize($files));
@@ -197,6 +208,9 @@ abstract class Folder
if (!$path) {
throw new \RuntimeException("Path doesn't exist.");
}
if (!file_exists($path)) {
return [];
}
$compare = isset($params['compare']) ? 'get' . $params['compare'] : null;
$pattern = $params['pattern'] ?? null;

View File

@@ -174,7 +174,7 @@ class Uri
$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();
@@ -218,7 +218,7 @@ class Uri
// 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);
}
@@ -365,7 +365,7 @@ class Uri
return $this->url;
}
$url = str_replace($this->base, '', rtrim($this->url, '/'));
$url = Utils::replaceFirstOccurrence($this->base, '', rtrim($this->url, '/'));
return $url ?: '/';
}
@@ -514,7 +514,7 @@ class Uri
return $this->uri;
}
return str_replace($this->root_path, '', $this->uri);
return Utils::replaceFirstOccurrence($this->root_path, '', $this->uri);
}
/**
@@ -556,7 +556,7 @@ class Uri
return $this->root;
}
return str_replace($this->base, '', $this->root);
return Utils::replaceFirstOccurrence($this->base, '', $this->root);
}
/**
@@ -808,7 +808,7 @@ class Uri
}
// 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 {
@@ -876,7 +876,7 @@ class Uri
}
// 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)) {
@@ -901,7 +901,7 @@ class Uri
// 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
@@ -1024,7 +1024,7 @@ class Uri
}
// 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;
}

View File

@@ -175,9 +175,13 @@ class Session implements SessionInterface
return $this;
}
$sessionName = session_name();
$sessionExists = isset($_COOKIE[$sessionName]);
// Protection against invalid session cookie names throwing exception: http://php.net/manual/en/function.session-id.php#116836
if (isset($_COOKIE[session_name()]) && !preg_match('/^[-,a-zA-Z0-9]{1,128}$/', $_COOKIE[session_name()])) {
unset($_COOKIE[session_name()]);
if ($sessionExists && !preg_match('/^[-,a-zA-Z0-9]{1,128}$/', $_COOKIE[$sessionName])) {
unset($_COOKIE[$sessionName]);
$sessionExists = false;
}
$options = $this->options;
@@ -203,17 +207,20 @@ class Session implements SessionInterface
throw new SessionException('Invalid User Object, restarting session', 500, $e);
}
$params = session_get_cookie_params();
// Extend the lifetime of the session.
if ($sessionExists) {
$params = session_get_cookie_params();
setcookie(
session_name(),
session_id(),
time() + $params['lifetime'],
$params['path'],
$params['domain'],
$params['secure'],
$params['httponly']
);
setcookie(
$sessionName,
session_id(),
time() + $params['lifetime'],
$params['path'],
$params['domain'],
$params['secure'],
$params['httponly']
);
}
$this->started = true;