non-standard lang code length fixes

This commit is contained in:
Andy Miller
2019-04-29 17:31:56 -06:00
parent 504c8faf4c
commit 4f83b5da5b
4 changed files with 15 additions and 3 deletions

View File

@@ -9,6 +9,7 @@
* Fixed `$grav['route']` from being modified when the route instance gets modified
* Fixed Assets options array mixed with standalone priority [#2477](https://github.com/getgrav/grav/issues/2477)
* Fix for `avatar_url` provided by 3rd party providers
* Fixed non standard `lang` code lengths in `Utils` and `Session` detection
# v1.6.8
## 04/23/2019

View File

@@ -104,6 +104,11 @@ class Language
public function getAvailable()
{
$languagesArray = $this->languages; //Make local copy
$languagesArray = array_map(function($value) {
return preg_quote($value);
}, $languagesArray);
sort($languagesArray);
return implode('|', array_reverse($languagesArray));

View File

@@ -13,6 +13,7 @@ use Grav\Common\Config\Config;
use Grav\Common\Debugger;
use Grav\Common\Session;
use Grav\Common\Uri;
use Grav\Common\Utils;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use RocketTheme\Toolbox\Session\Message;
@@ -55,8 +56,7 @@ class SessionServiceProvider implements ServiceProviderInterface
$current_route = str_replace(Uri::filterPath($uri->rootUrl(false)), '', parse_url($uri->url(true), PHP_URL_PATH));
// Check no language, simple language prefix (en) and region specific language prefix (en-US).
$pos = strpos($current_route, $base);
if ($pos === 0 || $pos === 3 || $pos === 6) {
if (Utils::startsWith($current_route, $base) || Utils::pathPrefixedByLangCode($current_route)) {
$cookie_lifetime = $config->get('plugins.admin.session.timeout', 1800);
$enabled = $is_admin = true;
}

View File

@@ -975,6 +975,7 @@ abstract class Utils
* @param string $string The path
*
* @return bool
*
*/
public static function pathPrefixedByLangCode($string)
{
@@ -983,8 +984,13 @@ abstract class Utils
}
$languages_enabled = Grav::instance()['config']->get('system.languages.supported', []);
$parts = explode('/', trim($string, '/'));
return $string[0] === '/' && $string[3] === '/' && \in_array(substr($string, 1, 2), $languages_enabled, true);
if (count($parts) > 0 && in_array($parts[0], $languages_enabled)) {
return true;
}
return false;
}
/**