You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2020/04/18 13:40:12 UTC

[httpcomponents-core] branch master updated: Fix CharArrayBuffer.subSequence(beganIndex, endIndex) to return right result.

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 5d8c512  Fix CharArrayBuffer.subSequence(beganIndex,endIndex) to return right result.
5d8c512 is described below

commit 5d8c5121e3eaee9e841a0935169131dc3b399e1b
Author: Lee Ray <li...@gmail.com>
AuthorDate: Sat Apr 18 20:59:57 2020 +0800

    Fix CharArrayBuffer.subSequence(beganIndex,endIndex) to return right result.
---
 .../main/java/org/apache/hc/core5/util/CharArrayBuffer.java    |  2 +-
 .../java/org/apache/hc/core5/util/TestCharArrayBuffer.java     | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/CharArrayBuffer.java b/httpcore5/src/main/java/org/apache/hc/core5/util/CharArrayBuffer.java
index 79eab23..40d2d5a 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/CharArrayBuffer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/CharArrayBuffer.java
@@ -485,7 +485,7 @@ public final class CharArrayBuffer implements CharSequence, Serializable {
         if (beginIndex > endIndex) {
             throw new IndexOutOfBoundsException("beginIndex: " + beginIndex + " > endIndex: " + endIndex);
         }
-        return CharBuffer.wrap(this.array, beginIndex, endIndex);
+        return CharBuffer.wrap(this.array, beginIndex, endIndex - beginIndex);
     }
 
     @Override
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/util/TestCharArrayBuffer.java b/httpcore5/src/test/java/org/apache/hc/core5/util/TestCharArrayBuffer.java
index 1fe85ee..9776249 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/util/TestCharArrayBuffer.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/util/TestCharArrayBuffer.java
@@ -400,6 +400,16 @@ public class TestCharArrayBuffer {
     }
 
     @Test
+    public void testSubSequence() {
+        final CharArrayBuffer buffer = new CharArrayBuffer(16);
+        buffer.append(" name:  value    ");
+        Assert.assertEquals(5, buffer.indexOf(':'));
+        Assert.assertEquals(" name", buffer.subSequence(0, 5).toString());
+        Assert.assertEquals("  value    ",
+            buffer.subSequence(6, buffer.length()).toString());
+    }
+
+    @Test
     public void testSubSequenceIndexOfOutBound() {
         final CharArrayBuffer buffer = new CharArrayBuffer(16);
         buffer.append("stuff");