This is an automated email from the ASF dual-hosted git repository.
elecharny pushed a commit to branch 2.0.X
in repository https://gitbox.apache.org/repos/asf/mina.git
The following commit(s) were added to refs/heads/2.0.X by this push:
new 995187ae2 Applied Thomas Wolf's patch for DIRMINA-1181
995187ae2 is described below
commit 995187ae223e092cb69452d95439f0c4863787ce
Author: emmanuel lecharny <[email protected]>
AuthorDate: Sat Sep 28 15:58:12 2024 +0200
Applied Thomas Wolf's patch for DIRMINA-1181
---
.../apache/mina/core/buffer/AbstractIoBuffer.java | 22 +++++-------------
.../{MacronTest.java => Utf16StringTest.java} | 26 +++++++++++++++++++++-
2 files changed, 31 insertions(+), 17 deletions(-)
diff --git
a/mina-core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java
b/mina-core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java
index 94a5058f0..4f3660934 100644
--- a/mina-core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java
+++ b/mina-core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java
@@ -1602,27 +1602,17 @@ public abstract class AbstractIoBuffer extends IoBuffer
{
newPos = end + 1;
}
} else {
- int i = oldPos;
- for (;;) {
- boolean wasZero = get(i) == 0;
- i++;
+ for (int i = oldPos; i < oldLimit;) {
+ byte b = get(i++);
if (i >= oldLimit) {
+ // Odd number of bytes...
break;
}
- if (get(i) != 0) {
- i++;
- if (i >= oldLimit) {
- break;
- }
-
- continue;
- }
-
- i++;
-
- if (wasZero) {
+ b |= get(i++);
+ if (b == 0) {
+ // 0x00 0x00 found.
end = i - 2;
break;
}
diff --git
a/mina-core/src/test/java/org/apache/mina/core/buffer/MacronTest.java
b/mina-core/src/test/java/org/apache/mina/core/buffer/Utf16StringTest.java
similarity index 77%
rename from mina-core/src/test/java/org/apache/mina/core/buffer/MacronTest.java
rename to
mina-core/src/test/java/org/apache/mina/core/buffer/Utf16StringTest.java
index 2a5cc134e..ab6055b12 100644
--- a/mina-core/src/test/java/org/apache/mina/core/buffer/MacronTest.java
+++ b/mina-core/src/test/java/org/apache/mina/core/buffer/Utf16StringTest.java
@@ -27,7 +27,7 @@ import java.nio.charset.StandardCharsets;
import org.junit.Test;
-public class MacronTest {
+public class Utf16StringTest {
/**
* Based on
mina-core\src\test\java\org\apache\mina\core\buffer\IoBufferTest.testGetString(CharsetDecoder)
* in branch 2.1.X
@@ -75,6 +75,30 @@ public class MacronTest {
buf.position(0);
assertEquals( "MĀORI", buf.getString(decoder) );
+
+ buf.clear();
+ buf.fillAndReset(buf.limit());
+
+ // now put "MĀORI" there: \u004d \u0100 \u004f \u0052 \u0049
+ // 01 00 00 00
+
+ buf = IoBuffer.allocate(16);
+ buf.put((byte) 0x01);
+ buf.put((byte) 0x00);
+
+ buf.position(0);
+
+ assertEquals( "Ā", buf.getString(decoder) );
+ }
+
+ @Test
+ public void testNotZeroTerminatedUtf16String() throws
CharacterCodingException {
+ IoBuffer buf = IoBuffer.allocate(2);
+ buf.put((byte) 0x01);
+ buf.put((byte) 0x00);
+ buf.position(0);
+ String decoded = buf.getString(StandardCharsets.UTF_16BE.newDecoder());
+ assertEquals("Ā", decoded);
}
}