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

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/master by this push:
     new e03f02d  JAMES-1808 if (character > 128) should be changed to if 
(character >= 128) (#634)
e03f02d is described below

commit e03f02d9faca40f2001b12eb3e25a2fe18ea216d
Author: Benoit TELLIER <[email protected]>
AuthorDate: Wed Sep 8 10:09:08 2021 +0700

    JAMES-1808 if (character > 128) should be changed to if (character >= 128) 
(#634)
    
    Not doing so results in (byte) character overflowing to -128:
    
    org.opentest4j.AssertionFailedError:
    expected: " "?"
    "
    but was : " "�"
    "
---
 .../imap/encode/base/ImapResponseComposerImpl.java |  2 +-
 .../imap/encode/ImapResponseComposerImplTest.java  | 47 ++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/encode/base/ImapResponseComposerImpl.java
 
b/protocols/imap/src/main/java/org/apache/james/imap/encode/base/ImapResponseComposerImpl.java
index 327e7d9..b6b5552 100644
--- 
a/protocols/imap/src/main/java/org/apache/james/imap/encode/base/ImapResponseComposerImpl.java
+++ 
b/protocols/imap/src/main/java/org/apache/james/imap/encode/base/ImapResponseComposerImpl.java
@@ -228,7 +228,7 @@ public class ImapResponseComposerImpl implements 
ImapConstants, ImapResponseComp
                 buffer.write(BYTE_BACK_SLASH);
             }
             // 7-bit ASCII only
-            if (character > 128) {
+            if (character >= 128) {
                 buffer.write(BYTE_QUESTION);
             } else {
                 buffer.write((byte) character);
diff --git 
a/protocols/imap/src/test/java/org/apache/james/imap/encode/ImapResponseComposerImplTest.java
 
b/protocols/imap/src/test/java/org/apache/james/imap/encode/ImapResponseComposerImplTest.java
new file mode 100644
index 0000000..593516f
--- /dev/null
+++ 
b/protocols/imap/src/test/java/org/apache/james/imap/encode/ImapResponseComposerImplTest.java
@@ -0,0 +1,47 @@
+/****************************************************************
+ * 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.james.imap.encode;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.imap.encode.base.ByteImapResponseWriter;
+import org.apache.james.imap.encode.base.ImapResponseComposerImpl;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+class ImapResponseComposerImplTest {
+    private ByteImapResponseWriter writer;
+    private ImapResponseComposer composer;
+
+    @BeforeEach
+    void setUp() {
+        writer = new ByteImapResponseWriter();
+        composer = new ImapResponseComposerImpl(writer);
+    }
+
+    @Test
+    void encodeShouldHandleQuotedChar128() throws Exception {
+        Character c = 128;
+        composer.quote(c.toString());
+        composer.end();
+
+        assertThat(writer.getString()).isEqualTo(" \"?\"\r\n");
+    }
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to