This is an automated email from the ASF dual-hosted git repository. jleroux pushed a commit to branch release18.12 in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/release18.12 by this push: new 8a3293a787 Fixed: Support non-breaking spaces in numeric strings (OFBIZ-13168) 8a3293a787 is described below commit 8a3293a78756827ddaec42456f1b1da59e1e5e58 Author: Jacques Le Roux <jacques.le.r...@les7arts.com> AuthorDate: Tue Nov 12 19:17:49 2024 +0100 Fixed: Support non-breaking spaces in numeric strings (OFBIZ-13168) In forms, numeric fields are represented by an input with type "text", which allows user to enter/paste all characters, including non-breaking spaces ('\u00A0', '\u202F', '\u2007'), like "29 000" (the space is \u202F). More specifically, a user can copy/paste a string from an external tool which uses non-breaking spaces as a thousands separator, and expect that a visually correct string will be correctly interpreted by OFBiz. OFBiz uses java.text.NumberFormat::parse method, which does not support non-breaking spaces : characters after this kind of spaces are simply ignored, and "29 000" becomes "29". Using [^\\p{IsAlnum}\\p{IsPunct}] regexp this replaces all chars that can be a problem for NumberFormat class. Conflicts handled by hand ObjectType.java ObjectTypeTests.java does not exists in 18.12 --- .../src/main/java/org/apache/ofbiz/base/util/ObjectType.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/ObjectType.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/ObjectType.java index 6d27f5cc85..17aa452395 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/ObjectType.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/ObjectType.java @@ -21,6 +21,7 @@ package org.apache.ofbiz.base.util; import java.io.Serializable; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.math.BigDecimal; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -156,7 +157,7 @@ public class ObjectType { * @throws ClassNotFoundException * @throws InstantiationException * @throws IllegalAccessException - * @throws NoSuchMethodException + * @throws NoSuchMethodException * @throws InvocationTargetException */ public static Object getInstance(String className) throws ClassNotFoundException, InstantiationException, @@ -559,6 +560,12 @@ public class ObjectType { } if (converter != null) { + // numeric types : replace everything that's not in [:IsAlnum:] or [:IsPunct:] classes by an empty string + List<?> numericClasses = UtilMisc.toList(BigDecimal.class, Double.class, Float.class, Long.class); + if (obj instanceof String && numericClasses.contains(targetClass)) { + obj = ((String) obj).replaceAll("[^\\p{IsAlnum}\\p{IsPunct}]", ""); + } + if (converter instanceof LocalizedConverter) { @SuppressWarnings("rawtypes") LocalizedConverter<Object, Object> localizedConverter = (LocalizedConverter) converter;