Skip to content

Commit

Permalink
[String] Fix ellipsis of truncate when not using cut option
Browse files Browse the repository at this point in the history
  • Loading branch information
duboiss authored and nicolas-grekas committed Jun 11, 2020
1 parent e5b5d9e commit a2ee6c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Symfony/Component/String/AbstractString.php
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,11 @@ public function truncate(int $length, string $ellipsis = '', bool $cut = true):
}

if (!$cut) {
$length = $ellipsisLength + ($this->indexOf([' ', "\r", "\n", "\t"], ($length ?: 1) - 1) ?? $stringLength);
if (null === $length = $this->indexOf([' ', "\r", "\n", "\t"], ($length ?: 1) - 1)) {
return clone $this;
}

$length += $ellipsisLength;
}

$str = $this->slice(0, $length - $ellipsisLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,7 @@ public static function provideTruncate()
['foobar...', 'foobar foo', 6, '...', false],
['foobar...', 'foobar foo', 7, '...', false],
['foobar foo...', 'foobar foo a', 10, '...', false],
['foobar foo aar', 'foobar foo aar', 12, '...', false],
];
}

Expand Down

0 comments on commit a2ee6c6

Please sign in to comment.