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

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-cli.git


The following commit(s) were added to refs/heads/master by this push:
     new f92c4ce0 reject non-BMP code points in the Character type converter 
(#425)
f92c4ce0 is described below

commit f92c4ce0f80fd09b648a9b73b6495417eb97edbf
Author: Digiscrypt Technologies <[email protected]>
AuthorDate: Sat Jul 11 17:49:47 2026 +0530

    reject non-BMP code points in the Character type converter (#425)
    
    Co-authored-by: digi-scrypt <[email protected]>
---
 src/main/java/org/apache/commons/cli/TypeHandler.java     | 11 ++++++++++-
 src/test/java/org/apache/commons/cli/TypeHandlerTest.java |  1 +
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/cli/TypeHandler.java 
b/src/main/java/org/apache/commons/cli/TypeHandler.java
index af913457..a9136759 100644
--- a/src/main/java/org/apache/commons/cli/TypeHandler.java
+++ b/src/main/java/org/apache/commons/cli/TypeHandler.java
@@ -230,7 +230,16 @@ public class TypeHandler {
         map.put(Integer.class, Integer::parseInt);
         map.put(Short.class, Short::parseShort);
         map.put(Byte.class, Byte::parseByte);
-        map.put(Character.class, s -> s.startsWith("\\u") ? 
Character.toChars(Integer.parseInt(s.substring(2), HEX_RADIX))[0] : 
s.charAt(0));
+        map.put(Character.class, s -> {
+            if (s.startsWith("\\u")) {
+                final int codePoint = Integer.parseInt(s.substring(2), 
HEX_RADIX);
+                if (!Character.isBmpCodePoint(codePoint)) {
+                    throw new IllegalArgumentException("Code point U+" + 
Integer.toHexString(codePoint) + " does not fit in a char");
+                }
+                return (char) codePoint;
+            }
+            return s.charAt(0);
+        });
         map.put(Double.class, Double::parseDouble);
         map.put(Float.class, Float::parseFloat);
         map.put(BigInteger.class, BigInteger::new);
diff --git a/src/test/java/org/apache/commons/cli/TypeHandlerTest.java 
b/src/test/java/org/apache/commons/cli/TypeHandlerTest.java
index 98745073..8b6b2182 100644
--- a/src/test/java/org/apache/commons/cli/TypeHandlerTest.java
+++ b/src/test/java/org/apache/commons/cli/TypeHandlerTest.java
@@ -134,6 +134,7 @@ class TypeHandlerTest {
         list.add(Arguments.of("5", Character.class, '5'));
         list.add(Arguments.of("5.5", Character.class, '5'));
         list.add(Arguments.of("\\u0124", Character.class, 
Character.toChars(0x0124)[0]));
+        list.add(Arguments.of("\\u1F600", Character.class, 
ParseException.class));
 
         list.add(Arguments.of("just-a-string", Double.class, 
ParseException.class));
         list.add(Arguments.of("5", Double.class, 5d));

Reply via email to