1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-22 20:51:10 +01:00

Get line count before truncating Paste snippets

Summary: Fixes T12338. Resolves an issue where long pastes would be truncated before getting a line count, resulting in an inaccurate line count being returned.

Test Plan: Made a large paste, verified that it displayed the correct number of lines.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin

Maniphest Tasks: T12338

Differential Revision: https://secure.phabricator.com/D17438
This commit is contained in:
Christopher Wetherill 2017-03-01 22:30:18 +00:00 committed by faulconbridge
parent 3f1ee67972
commit 5fad7eb1f9

View file

@ -185,7 +185,7 @@ final class PhabricatorPasteQuery
$paste->getFilePHID(),
$paste->getLanguage(),
'snippet',
'v2',
'v2.1',
PhabricatorHash::digestForIndex($paste->getTitle()),
));
}
@ -352,6 +352,9 @@ final class PhabricatorPasteQuery
$snippet_type = PhabricatorPasteSnippet::FULL;
$snippet = $paste->getRawContent();
$lines = phutil_split_lines($snippet);
$line_count = count($lines);
if (strlen($snippet) > 1024) {
$snippet_type = PhabricatorPasteSnippet::FIRST_BYTES;
$snippet = id(new PhutilUTF8StringTruncator())
@ -360,8 +363,6 @@ final class PhabricatorPasteQuery
->truncateString($snippet);
}
$lines = phutil_split_lines($snippet);
$line_count = count($lines);
if ($line_count > 5) {
$snippet_type = PhabricatorPasteSnippet::FIRST_LINES;
$snippet = implode('', array_slice($lines, 0, 5));