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 69948edbc Fix for DIRMINA-1181
69948edbc is described below

commit 69948edbced286cc9a804982c2be4122ace15c4e
Author: emmanuel lecharny <elecha...@apache.org>
AuthorDate: Fri Sep 27 11:58:49 2024 +0200

    Fix for DIRMINA-1181
---
 .../apache/mina/core/buffer/AbstractIoBuffer.java  |  4 +-
 .../org/apache/mina/core/buffer/MacronTest.java    | 82 ++++++++++++++++++++++
 2 files changed, 85 insertions(+), 1 deletion(-)

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 c281922e2..94a5058f0 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
@@ -1620,8 +1620,10 @@ public abstract class AbstractIoBuffer extends IoBuffer {
                     continue;
                 }
 
+                i++;
+
                 if (wasZero) {
-                    end = i - 1;
+                    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/MacronTest.java
new file mode 100644
index 000000000..e49d7e838
--- /dev/null
+++ b/mina-core/src/test/java/org/apache/mina/core/buffer/MacronTest.java
@@ -0,0 +1,82 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.mina.core.buffer;
+
+import static org.junit.Assert.assertEquals;
+
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.StandardCharsets;
+
+import org.junit.Test;
+
+public class MacronTest {
+    /**
+     * Based on 
mina-core\src\test\java\org\apache\mina\core\buffer\IoBufferTest.testGetString(CharsetDecoder)
+     * in branch 2.1.X
+     * 
+     * @throws CharacterCodingException
+     */
+    @Test
+    public void testMacron() throws CharacterCodingException {
+        IoBuffer buf = IoBuffer.allocate(16);
+
+        buf.clear();
+        buf.fillAndReset(buf.limit());
+        CharsetDecoder decoder = StandardCharsets.UTF_16BE.newDecoder();
+
+        buf.put((byte) 0);
+        buf.put((byte) 'A');
+        buf.put((byte) 0);
+        buf.put((byte) 'B');
+        buf.put((byte) 0);
+        buf.put((byte) 'C');
+        buf.put((byte) 0);
+        buf.put((byte) 0);
+
+        buf.position(0);
+        assertEquals( "ABC",  buf.getString(decoder) );
+        // all good
+
+        buf.clear();
+        buf.fillAndReset(buf.limit());
+
+        // now put "MĀORI" there: \u004d \u0100 \u004f \u0052 \u0049
+        // 00 4D 01 00 00 4F 00 52 00 49
+
+        buf = IoBuffer.allocate(16);
+        buf.put((byte) 0x00);
+        buf.put((byte) 0x4d);
+        buf.put((byte) 0x01);
+        buf.put((byte) 0x00);
+        buf.put((byte) 0x00);
+        buf.put((byte) 0x4f);
+        buf.put((byte) 0x00);
+        buf.put((byte) 0x52);
+        buf.put((byte) 0x00);
+        buf.put((byte) 0x49);
+        buf.put((byte) 0x00);
+
+        buf.position(0);
+        
+        assertEquals( "MĀORI",  buf.getString(decoder) );
+    }
+}
+

Reply via email to