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

pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git


The following commit(s) were added to refs/heads/trunk by this push:
     new e7545612b9 CodePageUtil: map Windows code pages 932 and 950 to 
Microsoft charsets (#1518)
e7545612b9 is described below

commit e7545612b9817dd36d4f53babb32b5b952ffd993
Author: nikhil1511 <[email protected]>
AuthorDate: Mon Nov 2 18:46:15 2026 +0530

    CodePageUtil: map Windows code pages 932 and 950 to Microsoft charsets 
(#1518)
    
    * CodePageUtil: map Windows code pages 932 and 950 to Microsoft charsets
    
    Map CP_SJIS (932) to MS932 / windows-31j instead of strict JIS X 0208
    Shift_JIS, and map code page 950 to MS950 / x-windows-950 instead of
    falling through to "cp950" (which resolves to IBM's x-IBM950 in Java).
    CP_MAC_JAPAN (10001) continues to return "SJIS".
    
    Closes #1514
    
    Generated-by: Google Gemini
    
    * Update HSMF TestBasics to expect MS950 for code page 950
    
    CodePageUtil.codepageToEncoding(950, true) now returns MS950
    (Microsoft's Big5 variant) instead of cp950, so the encoding guessed
    for chinese-traditional.msg changes accordingly.
---
 .../src/test/java/org/apache/poi/hsmf/TestBasics.java |  4 ++--
 .../main/java/org/apache/poi/util/CodePageUtil.java   | 19 ++++++++++++++++++-
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestBasics.java 
b/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestBasics.java
index 95185d39b7..913d0f8ab2 100644
--- a/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestBasics.java
+++ b/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestBasics.java
@@ -252,9 +252,9 @@ public final class TestBasics {
       // Defaults to CP1251
       assertEquals("CP1252", 
chinese.getRecipientDetailsChunks()[0].getRecipientDisplayNameChunk().get7BitEncoding());
 
-      // But after guessing goes to the correct one, cp950 (Windows 
Traditional Chinese)
+      // But after guessing goes to the correct one, MS950 (Microsoft's 
Windows Traditional Chinese Big5 variant)
       chinese.guess7BitEncoding();
-      assertEquals("cp950", 
chinese.getRecipientDetailsChunks()[0].getRecipientDisplayNameChunk().get7BitEncoding());
+      assertEquals("MS950", 
chinese.getRecipientDetailsChunks()[0].getRecipientDisplayNameChunk().get7BitEncoding());
    }
 
    @Disabled(value = "expected to fail")
diff --git a/poi/src/main/java/org/apache/poi/util/CodePageUtil.java 
b/poi/src/main/java/org/apache/poi/util/CodePageUtil.java
index be78d9feb0..ec4dd86294 100644
--- a/poi/src/main/java/org/apache/poi/util/CodePageUtil.java
+++ b/poi/src/main/java/org/apache/poi/util/CodePageUtil.java
@@ -436,7 +436,24 @@ public class CodePageUtil
             case CP_GB18030:
                 return "GB18030";
             case CP_SJIS:
-                return "SJIS";
+                // Windows code page 932 is Microsoft's Shift_JIS variant (IANA
+                // "Windows-31J"). Java's "SJIS" is JIS X 0208 Shift_JIS, which
+                // lacks the NEC and IBM extensions and maps some symbols
+                // differently.
+                if (javaLangFormat) {
+                    return "MS932";
+                } else {
+                    return "windows-31j";
+                }
+            case 950:
+                // Windows code page 950 is Microsoft's Big5 variant. Without
+                // this case, the default "cp950" resolves to IBM's variant
+                // (x-IBM950).
+                if (javaLangFormat) {
+                    return "MS950";
+                } else {
+                    return "x-windows-950";
+                }
             default:
                 return "cp" + codepage;
         }


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

Reply via email to