From 257d6cb6d8fbdc63d4e77a05056b8f122b255a38 Mon Sep 17 00:00:00 2001 From: Jeff Allen Date: Fri, 8 Jul 2022 08:19:01 +0100 Subject: [PATCH] Use language-neutral locale to infer Python class name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have long inferred the Python class name of many built-in classes from the Java implementation class name by truncation and toLowerCase(). This fails e.g. for "PyNotImplemented" in a Turkish locale where the lower-case of I is ı (dotless i). Thanks to Xiaoyin Liu for identifying the cause. We therefore use the language neutral "root" locale. Quite probably fixes #159. --- NEWS | 1 + src/org/python/core/PyJavaType.java | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 8a92c8d55..a2f035525 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,7 @@ Jython 2.7.3a1 - [ GH-178 ] Update icu4j JAR to 71.1 - [ GH-177 ] Update Ant to 1.10.12 (Gradle build) (CVE-2020-1945, 2021-36374) - [ GH-160 ] Improve context of "Cannot create PyString with non-byte value" + - [ GH-159 ] Non-byte PyString error during initialisation in Turkish locale - [ GH-158 ] Upgrade Bouncy Castle to 1.71 - [ GH-157 ] Upgrade ASM to 9.3 - [ GH-156 ] Replace custom SHA224 digest with Java's diff --git a/src/org/python/core/PyJavaType.java b/src/org/python/core/PyJavaType.java index 9a62722d1..fdb424c94 100644 --- a/src/org/python/core/PyJavaType.java +++ b/src/org/python/core/PyJavaType.java @@ -2,9 +2,6 @@ // Licensed to PSF under a Contributor Agreement. package org.python.core; -import org.python.core.util.StringUtil; -import org.python.util.Generic; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -37,15 +34,20 @@ import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Map; -import java.util.Map.Entry; import java.util.Queue; import java.util.Set; import java.util.Stack; +import org.python.core.util.StringUtil; +import org.python.util.Generic; + public class PyJavaType extends PyType { private final static Class[] OO = {PyObject.class, PyObject.class}; + private static final String CORE_PY = "org.python.core.Py"; + private static final int CORE_PY_LENGTH = CORE_PY.length(); // @formatter:off /** Deprecated methods in java.awt.* that have bean property equivalents we prefer. */ @@ -374,8 +376,8 @@ protected void init(Set needsInners) { name = forClass.getName(); // Strip the java fully qualified class name from Py classes in core - if (name.startsWith("org.python.core.Py")) { - name = name.substring("org.python.core.Py".length()).toLowerCase(); + if (name.startsWith(CORE_PY)) { + name = name.substring(CORE_PY_LENGTH).toLowerCase(Locale.ROOT); } dict = new PyStringMap();