ensure user attributes are truncated (#1580)
This commit is contained in:
@@ -23,7 +23,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
class InvoiceTemplate
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @var int|null
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Utils\StringHelper;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@@ -55,7 +56,7 @@ class User extends BaseUser implements UserInterface
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="alias", type="string", length=60, nullable=true)
|
||||
* @Assert\Length(max=160)
|
||||
* @Assert\Length(max=60)
|
||||
*/
|
||||
private $alias;
|
||||
|
||||
@@ -70,6 +71,7 @@ class User extends BaseUser implements UserInterface
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="title", type="string", length=50, nullable=true)
|
||||
* @Assert\Length(max=50)
|
||||
*/
|
||||
private $title;
|
||||
|
||||
@@ -77,6 +79,7 @@ class User extends BaseUser implements UserInterface
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="avatar", type="string", length=255, nullable=true)
|
||||
* @Assert\Length(max=255)
|
||||
*/
|
||||
private $avatar;
|
||||
|
||||
@@ -119,6 +122,7 @@ class User extends BaseUser implements UserInterface
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="auth", type="string", length=20, nullable=true)
|
||||
* @Assert\Length(max=20)
|
||||
*/
|
||||
private $auth = self::AUTH_INTERNAL;
|
||||
|
||||
@@ -152,7 +156,7 @@ class User extends BaseUser implements UserInterface
|
||||
|
||||
public function setAlias(?string $alias): User
|
||||
{
|
||||
$this->alias = $alias;
|
||||
$this->alias = StringHelper::ensureMaxLength($alias, 60);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -169,7 +173,7 @@ class User extends BaseUser implements UserInterface
|
||||
|
||||
public function setTitle(?string $title): User
|
||||
{
|
||||
$this->title = $title;
|
||||
$this->title = StringHelper::ensureMaxLength($title, 50);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class XlsxRenderer extends AbstractSpreadsheetRenderer
|
||||
$col = $sheet->getColumnDimension($column);
|
||||
|
||||
// If no other width is specified (which defaults to -1)
|
||||
if ($col->getWidth() === -1) {
|
||||
if ((int) $col->getWidth() === -1) {
|
||||
$col->setAutoSize(true);
|
||||
}
|
||||
}
|
||||
|
||||
26
src/Utils/StringHelper.php
Normal file
26
src/Utils/StringHelper.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Utils;
|
||||
|
||||
final class StringHelper
|
||||
{
|
||||
public static function ensureMaxLength(?string $string, int $length): ?string
|
||||
{
|
||||
if (null === $string) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (mb_strlen($string) > $length) {
|
||||
$string = mb_substr($string, 0, $length);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user