Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13978450
D14801.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D14801.diff
View Options
diff --git a/src/utils/PhutilRope.php b/src/utils/PhutilRope.php
--- a/src/utils/PhutilRope.php
+++ b/src/utils/PhutilRope.php
@@ -83,29 +83,29 @@
* @param int Bytes to remove.
* @return this
*/
- public function removeBytesFromHead($length) {
- if ($length <= 0) {
+ public function removeBytesFromHead($remove) {
+ if ($remove <= 0) {
throw new InvalidArgumentException(
pht('Length must be larger than 0!'));
}
- $remaining_length = $length;
+ $remaining_bytes = $remove;
foreach ($this->buffers as $key => $buf) {
$len = strlen($buf);
- if ($len <= $length) {
+ if ($len <= $remaining_bytes) {
unset($this->buffers[$key]);
- $remaining_length -= $len;
- if (!$remaining_length) {
+ $remaining_bytes -= $len;
+ if (!$remaining_bytes) {
break;
}
} else {
- $this->buffers[$key] = substr($buf, $length);
+ $this->buffers[$key] = substr($buf, $remaining_bytes);
break;
}
}
- if ($length <= $this->length) {
- $this->length -= $length;
+ if ($this->buffers) {
+ $this->length -= $remove;
} else {
$this->length = 0;
}
diff --git a/src/utils/__tests__/PhutilRopeTestCase.php b/src/utils/__tests__/PhutilRopeTestCase.php
--- a/src/utils/__tests__/PhutilRopeTestCase.php
+++ b/src/utils/__tests__/PhutilRopeTestCase.php
@@ -21,4 +21,36 @@
$this->assertEqual('', $rope->getAsString());
}
+ public function testMoreRopeOperations() {
+ $rope = new PhutilRope();
+ $rope->append('aaa');
+ $rope->append('bbb');
+ $rope->append('ccc');
+ $rope->append('rrrrddddddddd');
+ $rope->removeBytesFromHead(4);
+
+ $string = $rope->getAsString();
+ $this->assertEqual('bbcccrrrrddddddddd', $string);
+ $this->assertEqual(strlen($string), $rope->getByteLength());
+
+ $rope = new PhutilRope();
+ $rope->append('aaa');
+ $rope->append('bbb');
+ $rope->removeBytesFromHead(6);
+
+ $string = $rope->getAsString();
+ $this->assertEqual('', $string);
+ $this->assertEqual(0, $rope->getByteLength());
+
+
+ $rope = new PhutilRope();
+ $rope->append('a');
+ $rope->append('b');
+ $rope->append('c');
+ $rope->removeBytesFromHead(1024);
+
+ $string = $rope->getAsString();
+ $this->assertEqual('', $string);
+ $this->assertEqual(0, $rope->getByteLength());
+ }
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Oct 19, 11:14 PM (2 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6734253
Default Alt Text
D14801.diff (2 KB)
Attached To
Mode
D14801: Fix an issue with removing bytes in PhutilRope
Attached
Detach File
Event Timeline
Log In to Comment