1063-option-3 parserConfig set max len

This commit is contained in:
Sean Leary
2026-07-13 15:33:12 -05:00
parent 1efb5f6c43
commit 90563eb877
5 changed files with 191 additions and 57 deletions
+24 -4
View File
@@ -619,14 +619,30 @@ public class XML {
/**
* This method is the same as {@link JSONObject#stringToValue(String)}.
*
* @param string String to convert
* Warning! stringToValue(String) uses the default max number length. If you want to override it,
* use a suitable initialized XMLParserConfiguration and the method: stringToValue(String, XMLParserConfiguration).
* @param str String to convert
* @return JSON value of this string or the string
*/
// To maintain compatibility with the Android API, this method is a direct copy of
// the one in JSONObject. Changes made here should be reflected there.
// This method should not make calls out of the XML object.
public static Object stringToValue(String string) {
public static Object stringToValue(String str) {
return stringToValue(str, new XMLParserConfiguration());
}
/**
* This method is the same as {@link JSONObject#stringToValue(String)}.
*
* @param string String to convert
* @param xmlParserConfiguration the XML parser config object
* @return JSON value of this string or the string. If the string represents a number that is too large,
* a string will be returned.
*/
// To maintain compatibility with the Android API, this method is a direct copy of
// the one in JSONObject. Changes made here should be reflected there.
// This method should not make calls out of the XML object.
public static Object stringToValue(String string, XMLParserConfiguration xmlParserConfiguration) {
if ("".equals(string)) {
return string;
}
@@ -650,7 +666,11 @@ public class XML {
char initial = string.charAt(0);
if ((initial >= '0' && initial <= '9') || initial == '-') {
try {
if(string.length() <= 1000) {
// user declines max number checking
if (xmlParserConfiguration.getMaxNumberLength() == JSONParserConfiguration.UNDEFINED_MAXIMUM_NUMBER_LENGTH) {
return stringToNumber(string);
}
if(string.length() <= xmlParserConfiguration.getMaxNumberLength()) {
return stringToNumber(string);
}
} catch (Exception ignore) {