Author: fanningpj
Date: Tue Jun  2 10:38:28 2026
New Revision: 1934870

Log:
[XMLBEANS-664] reject non-ascii digits when lexing xsd integer types. Thanks to 
aizu-m. This closes #32

Added:
   xmlbeans/trunk/src/test/java/misc/checkin/XsTypeConverterTest.java
Modified:
   
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/util/XsTypeConverter.java

Modified: 
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/util/XsTypeConverter.java
==============================================================================
--- 
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/util/XsTypeConverter.java 
    Tue Jun  2 10:27:52 2026        (r1934869)
+++ 
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/util/XsTypeConverter.java 
    Tue Jun  2 10:38:28 2026        (r1934870)
@@ -619,7 +619,7 @@ public final class XsTypeConverter {
 
         for (int i = 0; i < length - start; i++) {
             c = ch.charAt(i + start);
-            int v = Character.digit(c, 10);
+            int v = (c >= '0' && c <= '9') ? c - '0' : -1;
 
             if (v < 0) {
                 throw new NumberFormatException("For input string: \"" + 
ch.toString() + "\"");
@@ -638,7 +638,7 @@ public final class XsTypeConverter {
     // ======================== anyURI ========================
 
     /**
-     * Checkes the regular expression of URI, defined by RFC2369 
http://www.ietf.org/rfc/rfc2396.txt Appendix B.
+     * Checks the regular expression of URI, defined by RFC2369 
http://www.ietf.org/rfc/rfc2396.txt Appendix B.
      * Note: The whitespace normalization rule collapse must be applied priot 
to calling this method.
      *
      * @param lexical_value the lexical value

Added: xmlbeans/trunk/src/test/java/misc/checkin/XsTypeConverterTest.java
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ xmlbeans/trunk/src/test/java/misc/checkin/XsTypeConverterTest.java  Tue Jun 
 2 10:38:28 2026        (r1934870)
@@ -0,0 +1,58 @@
+/*   Copyright 2026 The Apache Software Foundation
+ *
+ *   Licensed 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 misc.checkin;
+
+import org.apache.xmlbeans.impl.util.XsTypeConverter;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class XsTypeConverterTest {
+
+    // fullwidth "123", arabic-indic "123" and devanagari "123" are unicode
+    // decimal digits but outside the xsd lexical space.
+    private static final String FULLWIDTH_123 = "123";
+    private static final String ARABIC_123 = "١٢٣";
+    private static final String DEVANAGARI_123 = "१२३";
+
+    @Test
+    void lexIntAcceptsAscii() {
+        assertEquals(123, XsTypeConverter.lexInt("123"));
+        assertEquals(-123, XsTypeConverter.lexInt("-123"));
+        assertEquals(123, XsTypeConverter.lexInt("+123"));
+    }
+
+    @Test
+    void lexIntRejectsNonAsciiDigits() {
+        assertThrows(NumberFormatException.class, () -> 
XsTypeConverter.lexInt(FULLWIDTH_123));
+        assertThrows(NumberFormatException.class, () -> 
XsTypeConverter.lexInt(ARABIC_123));
+        assertThrows(NumberFormatException.class, () -> 
XsTypeConverter.lexInt(DEVANAGARI_123));
+    }
+
+    @Test
+    void lexShortRejectsNonAsciiDigits() {
+        assertEquals(123, XsTypeConverter.lexShort("123"));
+        assertThrows(NumberFormatException.class, () -> 
XsTypeConverter.lexShort(FULLWIDTH_123));
+        assertThrows(NumberFormatException.class, () -> 
XsTypeConverter.lexShort(ARABIC_123));
+    }
+
+    @Test
+    void lexByteRejectsNonAsciiDigits() {
+        assertEquals(123, XsTypeConverter.lexByte("123"));
+        assertThrows(NumberFormatException.class, () -> 
XsTypeConverter.lexByte(FULLWIDTH_123));
+        assertThrows(NumberFormatException.class, () -> 
XsTypeConverter.lexByte(ARABIC_123));
+    }
+}


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

Reply via email to