mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-02 09:58:24 +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:
parent
3f1ee67972
commit
5fad7eb1f9
1 changed files with 4 additions and 3 deletions
|
@ -185,7 +185,7 @@ final class PhabricatorPasteQuery
|
||||||
$paste->getFilePHID(),
|
$paste->getFilePHID(),
|
||||||
$paste->getLanguage(),
|
$paste->getLanguage(),
|
||||||
'snippet',
|
'snippet',
|
||||||
'v2',
|
'v2.1',
|
||||||
PhabricatorHash::digestForIndex($paste->getTitle()),
|
PhabricatorHash::digestForIndex($paste->getTitle()),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -352,6 +352,9 @@ final class PhabricatorPasteQuery
|
||||||
$snippet_type = PhabricatorPasteSnippet::FULL;
|
$snippet_type = PhabricatorPasteSnippet::FULL;
|
||||||
$snippet = $paste->getRawContent();
|
$snippet = $paste->getRawContent();
|
||||||
|
|
||||||
|
$lines = phutil_split_lines($snippet);
|
||||||
|
$line_count = count($lines);
|
||||||
|
|
||||||
if (strlen($snippet) > 1024) {
|
if (strlen($snippet) > 1024) {
|
||||||
$snippet_type = PhabricatorPasteSnippet::FIRST_BYTES;
|
$snippet_type = PhabricatorPasteSnippet::FIRST_BYTES;
|
||||||
$snippet = id(new PhutilUTF8StringTruncator())
|
$snippet = id(new PhutilUTF8StringTruncator())
|
||||||
|
@ -360,8 +363,6 @@ final class PhabricatorPasteQuery
|
||||||
->truncateString($snippet);
|
->truncateString($snippet);
|
||||||
}
|
}
|
||||||
|
|
||||||
$lines = phutil_split_lines($snippet);
|
|
||||||
$line_count = count($lines);
|
|
||||||
if ($line_count > 5) {
|
if ($line_count > 5) {
|
||||||
$snippet_type = PhabricatorPasteSnippet::FIRST_LINES;
|
$snippet_type = PhabricatorPasteSnippet::FIRST_LINES;
|
||||||
$snippet = implode('', array_slice($lines, 0, 5));
|
$snippet = implode('', array_slice($lines, 0, 5));
|
||||||
|
|
Loading…
Add table
Reference in a new issue