From: markt Date: Thu, 5 May 2011 13:39:09 +0000 (+0000) Subject: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47371 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=fdfccf7bf134cf25afdbb9c55b8c52f83edf62ea;p=tomcat7.0 Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47371 Correctly coerce the empty string to zero when used as an operand in EL arithmetic. Patch provided by gbt. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1099789 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/el/lang/ELArithmetic.java b/java/org/apache/el/lang/ELArithmetic.java index 7ae39f015..f0bb5b3ae 100644 --- a/java/org/apache/el/lang/ELArithmetic.java +++ b/java/org/apache/el/lang/ELArithmetic.java @@ -394,13 +394,12 @@ public abstract class ELArithmetic { if (isNumber(obj)) { return coerce((Number) obj); } - if (obj instanceof String) { - return coerce((String) obj); - } if (obj == null || "".equals(obj)) { return coerce(ZERO); } - + if (obj instanceof String) { + return coerce((String) obj); + } if (obj instanceof Character) { return coerce(Short.valueOf((short) ((Character) obj).charValue())); } diff --git a/test/org/apache/el/lang/TestELArithmetic.java b/test/org/apache/el/lang/TestELArithmetic.java index 305630b3a..c2dfd7f5d 100644 --- a/test/org/apache/el/lang/TestELArithmetic.java +++ b/test/org/apache/el/lang/TestELArithmetic.java @@ -49,4 +49,9 @@ public class TestELArithmetic extends TestCase { assertEquals("1.1", String.valueOf(ELArithmetic.mod(a, b))); } + + public void testBug47371() throws Exception { + assertEquals("1", + String.valueOf(ELArithmetic.add("", Integer.valueOf(1)))); + } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 506f1d626..9d5d77733 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -164,6 +164,10 @@ + + <47371/bug>: Correctly coerce the empty string to zero when used as + an operand in EL arithmetic. Patch provided by gbt. (markt) + Label JSP/tag file line and column numbers when reporting errors since it may not be immediately obvious what the numbers represent. (markt)