Bug 32896 - Invalid endsWith function
Summary: Invalid endsWith function
Status: RESOLVED FIXED
Alias: None
Product: Taglibs
Classification: Unclassified
Component: Standard Taglib (show other bugs)
Version: nightly
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL: http://cvs.apache.org/viewcvs.cgi/jak...
Keywords:
: 48848 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-12-30 21:19 UTC by Rastislav Rehak
Modified: 2010-03-22 01:29 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rastislav Rehak 2004-12-30 21:19:43 UTC
The function endsWith in standard library returns false also when the searched
substring is contained twice in string. 
Example : fn:endsWith( 'abcdb' ,'b' ) returns false.

Original source code :

    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());
    }  

should be :

    public static boolean endsWith(String input, String substring) {
        if (input == null) input = "";
        if (substring == null) substring = "";
        int index = input.lastIndexOf(substring);
        if (index == -1) return false;
        if (index == 0 && substring.length() == 0) return true;
        return (index == input.length() - substring.length());
    }
Comment 1 Dhiru Pandey 2005-02-17 02:33:19 UTC
Thanks for the fix Rastislav Rehak. The fix was committed by Pierre Delisle.

Marking this bug fixed.

-Dhiru
Comment 2 Henri Yandell 2010-03-22 01:29:43 UTC
*** Bug 48848 has been marked as a duplicate of this bug. ***