Skip to content

Commit 5fad7eb

Browse files
wethercfaulconbridge
authored and
faulconbridge
committedMar 1, 2017
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
1 parent 3f1ee67 commit 5fad7eb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed
 

‎src/applications/paste/query/PhabricatorPasteQuery.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private function getSnippetCacheKey(PhabricatorPaste $paste) {
185185
$paste->getFilePHID(),
186186
$paste->getLanguage(),
187187
'snippet',
188-
'v2',
188+
'v2.1',
189189
PhabricatorHash::digestForIndex($paste->getTitle()),
190190
));
191191
}
@@ -352,6 +352,9 @@ private function buildSnippet(PhabricatorPaste $paste) {
352352
$snippet_type = PhabricatorPasteSnippet::FULL;
353353
$snippet = $paste->getRawContent();
354354

355+
$lines = phutil_split_lines($snippet);
356+
$line_count = count($lines);
357+
355358
if (strlen($snippet) > 1024) {
356359
$snippet_type = PhabricatorPasteSnippet::FIRST_BYTES;
357360
$snippet = id(new PhutilUTF8StringTruncator())
@@ -360,8 +363,6 @@ private function buildSnippet(PhabricatorPaste $paste) {
360363
->truncateString($snippet);
361364
}
362365

363-
$lines = phutil_split_lines($snippet);
364-
$line_count = count($lines);
365366
if ($line_count > 5) {
366367
$snippet_type = PhabricatorPasteSnippet::FIRST_LINES;
367368
$snippet = implode('', array_slice($lines, 0, 5));

0 commit comments

Comments
 (0)
Failed to load comments.