Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15388040
D7783.id17619.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D7783.id17619.diff
View Options
Index: src/__phutil_library_map__.php
===================================================================
--- src/__phutil_library_map__.php
+++ src/__phutil_library_map__.php
@@ -779,6 +779,7 @@
'HeraldTranscriptController' => 'applications/herald/controller/HeraldTranscriptController.php',
'HeraldTranscriptListController' => 'applications/herald/controller/HeraldTranscriptListController.php',
'HeraldTranscriptQuery' => 'applications/herald/query/HeraldTranscriptQuery.php',
+ 'HeraldTranscriptTestCase' => 'applications/herald/storage/__tests__/HeraldTranscriptTestCase.php',
'Javelin' => 'infrastructure/javelin/Javelin.php',
'JavelinReactorExample' => 'applications/uiexample/examples/JavelinReactorExample.php',
'JavelinUIExample' => 'applications/uiexample/examples/JavelinUIExample.php',
@@ -3211,6 +3212,7 @@
'HeraldTranscriptController' => 'HeraldController',
'HeraldTranscriptListController' => 'HeraldController',
'HeraldTranscriptQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+ 'HeraldTranscriptTestCase' => 'PhabricatorTestCase',
'JavelinReactorExample' => 'PhabricatorUIExample',
'JavelinUIExample' => 'PhabricatorUIExample',
'JavelinViewExample' => 'PhabricatorUIExample',
Index: src/applications/herald/storage/__tests__/HeraldTranscriptTestCase.php
===================================================================
--- /dev/null
+++ src/applications/herald/storage/__tests__/HeraldTranscriptTestCase.php
@@ -0,0 +1,47 @@
+<?php
+
+final class HeraldTranscriptTestCase extends PhabricatorTestCase {
+
+ public function testTranscriptTruncation() {
+ $long_string = str_repeat('x', 1024 * 1024);
+ $short_string = str_repeat('x', 4096)."\n<...>";
+
+ $long_array = array(
+ 'a' => $long_string,
+ 'b' => $long_string,
+ );
+
+ $mixed_array = array(
+ 'a' => 'abc',
+ 'b' => 'def',
+ 'c' => $long_string,
+ );
+
+ $fields = array(
+ 'ls' => $long_string,
+ 'la' => $long_array,
+ 'ma' => $mixed_array,
+ );
+
+ $truncated_fields = id(new HeraldObjectTranscript())
+ ->setFields($fields)
+ ->getFields();
+
+ $this->assertEqual($short_string, $truncated_fields['ls']);
+
+ $this->assertEqual(
+ array('a', '<...>'),
+ array_keys($truncated_fields['la']));
+ $this->assertEqual(
+ $short_string.'!<...>',
+ implode('!', $truncated_fields['la']));
+
+ $this->assertEqual(
+ array('a', 'b', 'c'),
+ array_keys($truncated_fields['ma']));
+ $this->assertEqual(
+ 'abc!def!'.substr($short_string, 6),
+ implode('!', $truncated_fields['ma']));
+
+ }
+}
\ No newline at end of file
Index: src/applications/herald/storage/transcript/HeraldObjectTranscript.php
===================================================================
--- src/applications/herald/storage/transcript/HeraldObjectTranscript.php
+++ src/applications/herald/storage/transcript/HeraldObjectTranscript.php
@@ -35,6 +35,10 @@
}
public function setFields(array $fields) {
+ foreach ($fields as $key => $value) {
+ $fields[$key] = self::truncateValue($value, 4096);
+ }
+
$this->fields = $fields;
return $this;
}
@@ -42,4 +46,30 @@
public function getFields() {
return $this->fields;
}
+
+ private static function truncateValue($value, $length) {
+ if (is_string($value)) {
+ if (strlen($value) <= $length) {
+ return $value;
+ } else {
+ // NOTE: phutil_utf8_shorten() has huge runtime for giant strings.
+ return phutil_utf8ize(substr($value, 0, $length)."\n<...>");
+ }
+ } else if (is_array($value)) {
+ foreach ($value as $key => $v) {
+ if ($length <= 0) {
+ $value['<...>'] = '<...>';
+ unset($value[$key]);
+ } else {
+ $v = self::truncateValue($v, $length);
+ $length -= strlen($v);
+ $value[$key] = $v;
+ }
+ }
+ return $value;
+ } else {
+ return $value;
+ }
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 16, 3:14 AM (2 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7689428
Default Alt Text
D7783.id17619.diff (3 KB)
Attached To
Mode
D7783: Truncate object fields in Herald transcripts
Attached
Detach File
Event Timeline
Log In to Comment