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 6e98f5bd668..b2d2cdd973c 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 @@ -330,6 +330,12 @@ public static Object simpleTypeOrObjectConvert(Object obj, String type, String f } 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) { LocalizedConverter localizedConverter = UtilGenerics.cast(converter); if (timeZone == null) { diff --git a/framework/base/src/test/java/org/apache/ofbiz/base/util/ObjectTypeTests.java b/framework/base/src/test/java/org/apache/ofbiz/base/util/ObjectTypeTests.java index c6308597fd6..4b5ace55f5e 100644 --- a/framework/base/src/test/java/org/apache/ofbiz/base/util/ObjectTypeTests.java +++ b/framework/base/src/test/java/org/apache/ofbiz/base/util/ObjectTypeTests.java @@ -385,6 +385,12 @@ public void testString() throws GeneralException, Exception { new String[] {"TimeDuration", "org.apache.ofbiz.base.util.TimeDuration"}, duration); simpleTypeOrObjectConvertTestError("String->error-TimeDuration", "o", new String[] {"TimeDuration", "org.apache.ofbiz.base.util.TimeDuration"}); + + // usual pattern assumes that the String->BigDecimal conversion will break with bad timezone/locale + // which is not the case for this particular test + assertEquals("String->BigDecimal supports NBSP", + simpleTypeOrObjectConvert("29 000", "BigDecimal", null, LOCALE_DATA.goodTimeZone, + LOCALE_DATA.goodLocale, false), largeBigDecimal); } @Test