Skip to content

Commit d9b9505

Browse files
committed
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
1 parent 0559491 commit d9b9505

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

java/org/apache/el/lang/ELArithmetic.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,12 @@ protected final Number coerce(final Object obj) {
394394
if (isNumber(obj)) {
395395
return coerce((Number) obj);
396396
}
397-
if (obj instanceof String) {
398-
return coerce((String) obj);
399-
}
400397
if (obj == null || "".equals(obj)) {
401398
return coerce(ZERO);
402399
}
403-
400+
if (obj instanceof String) {
401+
return coerce((String) obj);
402+
}
404403
if (obj instanceof Character) {
405404
return coerce(Short.valueOf((short) ((Character) obj).charValue()));
406405
}

test/org/apache/el/lang/TestELArithmetic.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,9 @@ public void testMod() throws Exception {
4949
assertEquals("1.1",
5050
String.valueOf(ELArithmetic.mod(a, b)));
5151
}
52+
53+
public void testBug47371() throws Exception {
54+
assertEquals("1",
55+
String.valueOf(ELArithmetic.add("", Integer.valueOf(1))));
56+
}
5257
}

webapps/docs/changelog.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@
164164
</subsection>
165165
<subsection name="Jasper">
166166
<changelog>
167+
<fix>
168+
<bug><47371/bug>: Correctly coerce the empty string to zero when used as
169+
an operand in EL arithmetic. Patch provided by gbt. (markt)
170+
</fix>
167171
<add>
168172
Label JSP/tag file line and column numbers when reporting errors since
169173
it may not be immediately obvious what the numbers represent. (markt)

0 commit comments

Comments
 (0)