Bug 48848

Summary: fn:endsWith fails with repeated search string
Product: Taglibs Reporter: Jose Miguel Samper <jmiguelss>
Component: Standard TaglibAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED DUPLICATE    
Severity: major    
Priority: P2    
Version: 1.1   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: JSP which reproduces bug
Simpler JSP which reproduces the bug

Description Jose Miguel Samper 2010-03-03 10:41:52 UTC
${fn:endsWith('$21', '1')} returns true, but
${fn:endsWith('$22', '2')} returns false.

Both comparisons should return true.

Standard taglib version is 1.1.2.

Tested on Tomcat 6.0.18 and Glassfish v3.
Comment 1 Jose Miguel Samper 2010-03-07 13:34:16 UTC
Created attachment 25101 [details]
JSP which reproduces bug

Drop JSP into web application to see the bug.

Of course, you need standard-taglibs in the classpath.
Comment 2 Konstantin Kolinko 2010-03-07 13:44:26 UTC
Wow! Indeed, broken. Can reproduce it with 6.0.24.

In org\apache\taglibs\standard\functions\Functions.java:
    public static boolean endsWith(String input, String substring) {
        if (input == null) input = "";
        if (substring == null) substring = "";
        int index = input.indexOf(substring);
        if (index == -1) return false;
        if (index == 0 && substring.length() == 0) return true;
        return (index == input.length() - substring.length());
    }  
there must be
        int index = input.lastIndexOf(substring);

though I more wonder why it does not just use
  String.endsWith(String)
like fn:startsWith already does.
Comment 3 Jose Miguel Samper 2010-03-07 13:59:47 UTC
Created attachment 25102 [details]
Simpler JSP which reproduces the bug

The bug has nothing to do with dollar sign, so I change the testcase.
Comment 4 Jose Miguel Samper 2010-03-07 14:00:45 UTC
The bug has nothing to do with dollar sign, so I changed the bug summary.
Comment 5 Jose Miguel Samper 2010-03-08 08:45:04 UTC
This bug is the same as bug #32896 

Bug #32896 was fixed in 2005!!! but standard-taglibs project has not released any version since 2004.
Comment 6 Henri Yandell 2010-03-22 01:29:43 UTC

*** This bug has been marked as a duplicate of bug 32896 ***