diff --git a/CHANGELOG.md b/CHANGELOG.md index d6504836f..1dc494da8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# v1.4.5 +## 05/15/2018 + +1. [](#bugfix) + * Fixed an issue with some users getting **2FA** prompt after upgrade [admin#1442](https://github.com/getgrav/grav-plugin-admin/issues/1442) + * Do not crash when generating URLs with arrays as parameters [#2018](https://github.com/getgrav/grav/pull/2018) + * Utils::truncateHTML removes whitespace when generating summaries [#2004](https://github.com/getgrav/grav/pull/2004) + # v1.4.4 ## 05/11/2018 diff --git a/system/defines.php b/system/defines.php index 28fe50246..5d02c474c 100644 --- a/system/defines.php +++ b/system/defines.php @@ -8,7 +8,7 @@ // Some standard defines define('GRAV', true); -define('GRAV_VERSION', '1.4.4'); +define('GRAV_VERSION', '1.4.5'); define('GRAV_TESTING', false); define('DS', '/'); diff --git a/system/src/Grav/Common/Helpers/Truncator.php b/system/src/Grav/Common/Helpers/Truncator.php index c2e734989..b2a19dbc2 100644 --- a/system/src/Grav/Common/Helpers/Truncator.php +++ b/system/src/Grav/Common/Helpers/Truncator.php @@ -47,6 +47,7 @@ class Truncator { // Iterate over words. $words = new DOMWordsIterator($body); + $truncated = false; foreach ($words as $word) { // If we have exceeded the limit, we delete the remainder of the content. @@ -70,12 +71,19 @@ class Truncator { self::insertEllipsis($curNode, $ellipsis); } + $truncated = true; + break; } } - return self::innerHTML($body); + // Return original HTML if not truncated. + if ($truncated) { + return self::innerHTML($body); + } else { + return $html; + } } /** @@ -98,6 +106,7 @@ class Truncator { // Iterate over letters. $letters = new DOMLettersIterator($body); + $truncated = false; foreach ($letters as $letter) { // If we have exceeded the limit, we want to delete the remainder of this document. @@ -111,11 +120,18 @@ class Truncator { self::insertEllipsis($currentText[0], $ellipsis); } + $truncated = true; + break; } } - return self::innerHTML($body); + // Return original HTML if not truncated. + if ($truncated) { + return self::innerHTML($body); + } else { + return $html; + } } /** diff --git a/system/src/Grav/Common/Page/Medium/Medium.php b/system/src/Grav/Common/Page/Medium/Medium.php index 1c1c60f89..673368054 100644 --- a/system/src/Grav/Common/Page/Medium/Medium.php +++ b/system/src/Grav/Common/Page/Medium/Medium.php @@ -536,7 +536,12 @@ class Medium extends Data implements RenderableInterface { $qs = $method; if (count($args) > 1 || (count($args) == 1 && !empty($args[0]))) { - $qs .= '=' . implode(',', array_map(function ($a) { return rawurlencode($a); }, $args)); + $qs .= '=' . implode(',', array_map(function ($a) { + if (is_array($a)) { + $a = '[' . implode(',', $a) . ']'; + } + return rawurlencode($a); + }, $args)); } if (!empty($qs)) { diff --git a/system/src/Grav/Common/User/User.php b/system/src/Grav/Common/User/User.php index c1e628d50..512b29203 100644 --- a/system/src/Grav/Common/User/User.php +++ b/system/src/Grav/Common/User/User.php @@ -95,11 +95,41 @@ class User extends Data public static function remove($username) { $file_path = Grav::instance()['locator']->findResource('account://' . $username . YAML_EXT); - if ($file_path && unlink($file_path)) { - return true; + + return $file_path && unlink($file_path); + } + + /** + * @param string $offset + * @return bool + */ + public function offsetExists($offset) + { + $value = parent::offsetExists($offset); + + // Handle special case where user was logged in before 'authorized' was added to the user object. + if (false === $value && $offset === 'authorized') { + $value = $this->offsetExists('authenticated'); } - return false; + return $value; + } + + /** + * @param string $offset + * @return mixed + */ + public function offsetGet($offset) + { + $value = parent::offsetGet($offset); + + // Handle special case where user was logged in before 'authorized' was added to the user object. + if (null === $value && $offset === 'authorized') { + $value = $this->offsetGet('authenticated'); + $this->offsetSet($offset, $value); + } + + return $value; } /** diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index 2736fd904..02d5e158a 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -296,10 +296,6 @@ abstract class Utils */ public static function truncateHtml($text, $length = 100, $ellipsis = '...') { - if (mb_strlen($text) <= $length) { - return $text; - } - return Truncator::truncateLetters($text, $length, $ellipsis); } diff --git a/tests/unit/Grav/Common/UtilsTest.php b/tests/unit/Grav/Common/UtilsTest.php index c4abc32ac..889a7db3b 100644 --- a/tests/unit/Grav/Common/UtilsTest.php +++ b/tests/unit/Grav/Common/UtilsTest.php @@ -127,7 +127,7 @@ class UtilsTest extends \Codeception\TestCase\Test $this->assertEquals('
This...
', Utils::truncateHtml('This is a string to truncate
', 4)); $this->assertEquals('This is a...
', Utils::truncateHtml('This is a string to truncate
', 10)); $this->assertEquals('This is a string to truncate
', Utils::truncateHtml('This is a string to truncate
', 100)); - $this->assertEquals('', Utils::truncateHtml('', 6)); + $this->assertEquals('', Utils::truncateHtml('', 6)); $this->assertEquals('This is a string.
\nIt splits two lines.
", Utils::truncateHtml("This is a string.
\nIt splits two lines.
", 100)); } @@ -138,7 +138,7 @@ class UtilsTest extends \Codeception\TestCase\Test $this->assertEquals('This is...
', Utils::safeTruncateHtml('This is a string to truncate
', 2)); $this->assertEquals('This is a string to...
', Utils::safeTruncateHtml('This is a string to truncate
', 5)); $this->assertEquals('This is a string to truncate
', Utils::safeTruncateHtml('This is a string to truncate
', 20)); - $this->assertEquals('', Utils::safeTruncateHtml('', 6)); + $this->assertEquals('', Utils::safeTruncateHtml('', 6)); $this->assertEquals('