diff --git a/core/src/main/java/lucee/runtime/op/Caster.java b/core/src/main/java/lucee/runtime/op/Caster.java index 01ec7c7eb0..0336c8a13a 100755 --- a/core/src/main/java/lucee/runtime/op/Caster.java +++ b/core/src/main/java/lucee/runtime/op/Caster.java @@ -806,30 +806,6 @@ public static int toIntValue(Object o) throws PageException { throw new CasterException(o, "number"); } - /** - * cast an Object to an int value (primitive value type) - * - * @param o Object to cast - * @param defaultValue - * @return casted int value - */ - public static int toIntValue(Object o, int defaultValue) { - - if (o instanceof Number) return ((Number) o).intValue(); - else if (o instanceof Boolean) return ((Boolean) o).booleanValue() ? 1 : 0; - else if (o instanceof CharSequence) return toIntValue(o.toString().trim(), defaultValue); - // else if(o instanceof Clob) return toIntValue(toString(o)); - else if (o instanceof Character) return (((Character) o).charValue()); - else if (o instanceof Castable) { - return (int) ((Castable) o).castToDoubleValue(defaultValue); - - } - else if (o instanceof Date) return (int) new DateTimeImpl((Date) o).castToDoubleValue(); - else if (o instanceof ObjectWrap) return toIntValue(((ObjectWrap) o).getEmbededObject(Integer.valueOf(defaultValue)), defaultValue); - - return defaultValue; - } - public static int toIntValue(Integer i, int defaultValue) { if (i == null) return defaultValue; return i.intValue(); @@ -4843,6 +4819,12 @@ public static Integer toInteger(String str) throws PageException { return Integer.valueOf(toIntValue(str)); } + public static Integer toInteger(String str, Integer defaultValue) { + Double d = toDouble(str, null); + if (d == null) return defaultValue; + return Integer.valueOf(d.intValue()); + } + // used in bytecode genrator public static Integer toInteger(int i) { return Integer.valueOf(i); @@ -4856,10 +4838,32 @@ public static Integer toInteger(int i) { * @return Integer from Object */ public static Integer toInteger(Object o, Integer defaultValue) { - if (defaultValue != null) return Integer.valueOf(toIntValue(o, defaultValue.intValue())); - int res = toIntValue(o, Integer.MIN_VALUE); - if (res == Integer.MIN_VALUE) return defaultValue; - return Integer.valueOf(res); + + if (o instanceof Number) return Integer.valueOf(((Number) o).intValue()); + else if (o instanceof Boolean) return Integer.valueOf(((Boolean) o).booleanValue() ? 1 : 0); + else if (o instanceof CharSequence) return toInteger(o.toString().trim(), defaultValue); + // else if(o instanceof Clob) return toIntValue(toString(o)); + else if (o instanceof Character) return Integer.valueOf(((Character) o).charValue()); + else if (o instanceof Castable) { + return Integer.valueOf((int) ((Castable) o).castToDoubleValue(defaultValue)); + + } + else if (o instanceof Date) return Integer.valueOf((int) new DateTimeImpl((Date) o).castToDoubleValue()); + else if (o instanceof ObjectWrap) return toInteger(((ObjectWrap) o).getEmbededObject(Integer.valueOf(defaultValue)), defaultValue); + return defaultValue; + } + + /** + * cast an Object to an int value (primitive value type) + * + * @param o Object to cast + * @param defaultValue + * @return casted int value + */ + public static int toIntValue(Object o, int defaultValue) { + Integer i = toInteger(o, null); + if (i == null) return defaultValue; + return i.intValue(); } /** diff --git a/loader/build.xml b/loader/build.xml index 9369f73347..8c4e38282b 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index 36f819c8f7..f96542fbe1 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.2.0.196-SNAPSHOT + 6.2.0.197-SNAPSHOT jar Lucee Loader Build diff --git a/test/tickets/LDEV2793.cfc b/test/tickets/LDEV2793.cfc index 7caa156e23..61e1172cf6 100644 --- a/test/tickets/LDEV2793.cfc +++ b/test/tickets/LDEV2793.cfc @@ -44,7 +44,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="java" { }); - it( title='test parseDateTime (preciseMath=false)', skip=true, body=function() { + it( title='test parseDateTime (preciseMath=false)', body=function() { application action="update" preciseMath=false; var projects = [ { @@ -73,5 +73,4 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="java" { }); }); } - } \ No newline at end of file