Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita2ee6c6

Browse files
duboissnicolas-grekas
authored andcommitted
[String] Fix ellipsis of truncate when not using cut option
1 parente5b5d9e commita2ee6c6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

‎src/Symfony/Component/String/AbstractString.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,11 @@ public function truncate(int $length, string $ellipsis = '', bool $cut = true):
643643
}
644644

645645
if (!$cut) {
646-
$length =$ellipsisLength + ($this->indexOf(['',"\r","\n","\t"], ($length ?:1) -1) ??$stringLength);
646+
if (null ===$length =$this->indexOf(['',"\r","\n","\t"], ($length ?:1) -1)) {
647+
returnclone$this;
648+
}
649+
650+
$length +=$ellipsisLength;
647651
}
648652

649653
$str =$this->slice(0,$length -$ellipsisLength);

‎src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,7 @@ public static function provideTruncate()
14501450
['foobar...','foobar foo',6,'...',false],
14511451
['foobar...','foobar foo',7,'...',false],
14521452
['foobar foo...','foobar foo a',10,'...',false],
1453+
['foobar foo aar','foobar foo aar',12,'...',false],
14531454
];
14541455
}
14551456

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp