Merge branch 'release/1.4.5'

This commit is contained in:
Andy Miller
2018-05-15 12:55:39 -06:00
7 changed files with 68 additions and 13 deletions

View File

@@ -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

View File

@@ -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', '/');

View File

@@ -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;
}
}
/**

View File

@@ -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)) {

View File

@@ -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;
}
/**

View File

@@ -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);
}

View File

@@ -127,7 +127,7 @@ class UtilsTest extends \Codeception\TestCase\Test
$this->assertEquals('<p>This...</p>', Utils::truncateHtml('<p>This is a string to truncate</p>', 4));
$this->assertEquals('<p>This is a...</p>', Utils::truncateHtml('<p>This is a string to truncate</p>', 10));
$this->assertEquals('<p>This is a string to truncate</p>', Utils::truncateHtml('<p>This is a string to truncate</p>', 100));
$this->assertEquals('<input type="file" id="file" multiple>', Utils::truncateHtml('<input type="file" id="file" multiple />', 6));
$this->assertEquals('<input type="file" id="file" multiple />', Utils::truncateHtml('<input type="file" id="file" multiple />', 6));
$this->assertEquals('<ol><li>item 1 <i>so...</i></li></ol>', Utils::truncateHtml('<ol><li>item 1 <i>something</i></li><li>item 2 <strong>bold</strong></li></ol>', 10));
$this->assertEquals("<p>This is a string.</p>\n<p>It splits two lines.</p>", Utils::truncateHtml("<p>This is a string.</p>\n<p>It splits two lines.</p>", 100));
}
@@ -138,7 +138,7 @@ class UtilsTest extends \Codeception\TestCase\Test
$this->assertEquals('<p>This is...</p>', Utils::safeTruncateHtml('<p>This is a string to truncate</p>', 2));
$this->assertEquals('<p>This is a string to...</p>', Utils::safeTruncateHtml('<p>This is a string to truncate</p>', 5));
$this->assertEquals('<p>This is a string to truncate</p>', Utils::safeTruncateHtml('<p>This is a string to truncate</p>', 20));
$this->assertEquals('<input type="file" id="file" multiple>', Utils::safeTruncateHtml('<input type="file" id="file" multiple />', 6));
$this->assertEquals('<input type="file" id="file" multiple />', Utils::safeTruncateHtml('<input type="file" id="file" multiple />', 6));
$this->assertEquals('<ol><li>item 1 <i>something</i></li><li>item 2...</li></ol>', Utils::safeTruncateHtml('<ol><li>item 1 <i>something</i></li><li>item 2 <strong>bold</strong></li></ol>', 5));
}